http://www.quora.com/How-do-you-judge-a-Javascript-programmer-by-only-5-questions
diff between call and apply
call accepts parameters explicitly ... comma seperated
apply accepts array of parameter
call : comma
apply : array
theFunction.apply(param1, ["test1", "test2"]);
theFunction.call(param1, "test1", "test2");
javascript : map and reduce
The reduce() method applies a function against an accumulator and each value of the array (from left-to-right) has to reduce it to a single value.
[0, 1, 2, 3, 4].reduce(function(previousValue, currentValue, index, array) {
return previousValue + currentValue;
});
The map() method creates a new array with the results of calling a provided function on every element in this array.
var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt);
// roots is now [1, 2, 3], numbers is still [1, 4, 9]
diff between call and apply
call accepts parameters explicitly ... comma seperated
apply accepts array of parameter
call : comma
apply : array
theFunction.apply(param1, ["test1", "test2"]);
theFunction.call(param1, "test1", "test2");
javascript : map and reduce
The reduce() method applies a function against an accumulator and each value of the array (from left-to-right) has to reduce it to a single value.
[0, 1, 2, 3, 4].reduce(function(previousValue, currentValue, index, array) {
return previousValue + currentValue;
});
The map() method creates a new array with the results of calling a provided function on every element in this array.
var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt);
// roots is now [1, 2, 3], numbers is still [1, 4, 9]
No comments:
Post a Comment