Академический Документы
Профессиональный Документы
Культура Документы
//
sk.
//
//
Define a function filter, which checks the boolean value of the callback on t
element of collection
Here is where it gets tricky
The interviewer can ask many ways for filter to be defined.
Below covers the basic idea
You will have to modify the version they ask to fit the situation they want
return temp_solution;
};
// Define a function reduce, which has an initial input value and uses the call
back on the elements of collection.
// This is the final question and the most difficult question in the interview.
I've left the format.
// Look up what reduce does and how it operates. Then figure out how to write
it from scratch.
// example, callback is sum of array, [1,2,3,4,5], initialValue is 0
-> 15
// example, callback is difference of an array, [1,2,3,4,5], initialValue is 0
-> -15
// example, callback is difference of an array, [1,2,3,4,-5], initialValue is 0
-> -5
// example, callback is multiplication of an array, [1,2,3,4,5], initialValue i
s 1 -> 120
// The point is, to write it so that the callback, whatever it is (add, mult, s
ubtract, etc.), makes changes to the initialValue and returns initialValue
var reduce = function(collection, callback, initialValue){
};