I quite like the idea (and .some and .every are lovely), but this implementations is somewhat misleading to read:
All the checks are always performed at the time they're added, even though the power in some is that it break;s after the first hit.
I think this is a good opportunity for some higher level functions:
Overall I like the idea, but I think it will seldom be sufficient to deal with just a boolean as output. And if it is that simple, I'd prefer good ol' if/else.
The problem is how do you know what the piece of data that is invalid age or username or something (you need to have additional code). And what if you want to throw custom error message for each case?
Array in JS is also weird (if you dont know the spec of map or using Typescript)
I'd prefer a ternary over the if-else, but changing the tests to a list of functions is excellent. Adding, updating, removing tests becomes dead simple at this point and it's easier to test.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I quite like the idea (and
.some
and.every
are lovely), but this implementations is somewhat misleading to read:All the checks are always performed at the time they're added, even though the power in
some
is that itbreak;
s after the first hit.I think this is a good opportunity for some higher level functions:
Overall I like the idea, but I think it will seldom be sufficient to deal with just a boolean as output. And if it is that simple, I'd prefer good ol' if/else.
So it's a 🤢 from me
The problem is how do you know what the piece of data that is invalid
age
orusername
or something (you need to have additional code). And what if you want to throw custom error message for each case?Array in JS is also weird (if you dont know the spec of
map
or using Typescript)It can cause debuging becomes nightmare!
So I prefer
if-else
.Yea, this was my reaction as well; when a simple
if
isn't enough anymore, higher-order functions is the way to go.However, I'd add the data as its own argument to make things more convenient:
good example! 😍
this 👍
I'd prefer a ternary over the if-else, but changing the tests to a list of functions is excellent. Adding, updating, removing tests becomes dead simple at this point and it's easier to test.