I am trying to filter an array using the some function as a callback and have only elements which are multipliers of the other array.
function sumOfNumbersDivisibleByAnyFunctional(upTo) {
var numbers = [];
for(var i = 0;i<=upTo; i +=1){
numbers.push(i);
}
function filterByArr(arr){
return function (el){
return arr.some(multiplier => el % multiplier === 0);
}
}
return numbers.filter(filterByArr(arguments));
}
But no matter how I tried I am getting an error saying the arr.some
is not a function.
Any idea what I am missing?
I also tried:
return numbers.filter(noToTest => arguments.some(multiplier => noToTest % multiplier === 0));
If this is called:
sumOfNumbersDivisibleByAnyFunctional(10,3,5)
it will create an array of numbers between 0-10 and return only ones that are multipliers of 3 or 5.
I don't this this should be closed as duplicate of How can I convert the “arguments” object to an array in JavaScript?
. As mentioned this is the issue with the code above but does not answer the original question. for reference I would leave the question open and post n answer explaining the correct solution.