Skip to content

Instantly share code, notes, and snippets.

@mrutid
Created November 13, 2013 11:16
Show Gist options
  • Save mrutid/7447424 to your computer and use it in GitHub Desktop.
Save mrutid/7447424 to your computer and use it in GitHub Desktop.
Hace lo que tiene que hacer, aunque no me gusta como acumulo.Prefiero un array de cadenas. Pasan los test de checkeo pero he roto algo... que no deberia tener que ver....
/*
for (var field in fields) {
if (typeof body[fields[field]] == 'undefined') {
callback({
code: "FIELDS_MISSING",
field: fields[field]
});
return;
}
}
*/
function checkField(field) {
return (typeof body[field] === 'undefined');
}
function packErrors(prev, current) {
prev += current;
return prev;
}
var errors = fields.filter(checkField).reduce(packErrors, '');
if (errors !== '') {
callback({
code: "FIELDS_MISSING",
field: errors
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment