I need to know how to solve this problem I've read from internet.
With a given array I need find all uniques elements and minus than 10. Then do the sumatory of all of them. And later multiply each array value by this number (the sumatory).
I'm assuming I can use reduce to do the sumatory and map to multiply but I don't know really how it works and I'm stuck. Also to find the unique element is not easy.
I have the entry values and expected ones.
Input, expected
[1], [1]
[1, 1, 2], [2, 2, 4]
[0, 0, 1, 2, 1], [0, 0, 2, 4, 2]
[0, 10, 1, 1, 20, 3, 40, 3], [0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 2, 4, 11], [0, 6, 6, 12, 24, 66]
[10, 1, 1, 1], [0, 0, 0, 0]
[10, 11, 1, 2, 3, 4], [100, 110, 10, 20, 30, 40]
I'm trying a few things, but the main problem is I don't understand the syntaxis I think. I know how to solve this iterating through a loop, but I want learn by high order functions.
This is not a school project, I'm learning about this, so I don't need only the solution, I would like to understand, thanks.
What I tried is apply map like this. And also filter and reduce
var input = [0, 0, 1, 2, 1]
var output = [0, 0, 2, 4, 2]
var map, reduce, filter;
map = input.map(multiplyFunction(first,second))
function multiplyFunction(first,second){
return first*second
}