I have an array of reasons a password has failed validation:
const failures = schema.validate(password.value, { list: true });
console.log(failues);
// => [ 'min', 'uppercase', 'digits' ]
I also have an array of objects. The key is always a potential value of the failures array:
const msg = [
{ key: 'min', message: 'minimum' },
{ key: 'max', message: 'maximum' },
{ key: 'uppercase', message: 'need a uppercase' },
{ key: 'lowercase', message: 'need a lowercase' },
{ key: 'digits', message: 'must have digits' },
{ key: 'spaces', message: 'no spaces' },
{ key: 'oneOf', message: 'is not one of' },
];
I want to map over the failures array and return the relevant message from msg to display a more coherent error message.