Yeah, it’s failing because in the function you’ve returned (the return value => value+arguments[0] bit) you aren’t error-checking what might get passed to THAT function for numeric value.
Expand your arrow function there just a little:
return (value) => {
if (/* check that value is valid here */){
// What do you think this should be for a valid value?
else {
// And what do you return for a non-numeric value?
}
}
Or, if you like the single-line syntax (in this case, makes my brain itch):
return (value) => typeof(value)=='number' ? value + arguments[0] : undefined;
My goodness, that’s ugly. To expand that out completely, so that it may make a little more sense:
// I'll define a function as a variable, so I can simply toss it around by name!
let myReturnFunc = function(value){
if (typeof value == 'number'){
return value + arguments[0];
} else {
return undefined;
}
// Now, in the event that we only got a single value in the first parens, we are going to
// return that function we just made.
return myReturnFunc;
}