Hey guys, I am following along to a JS video on udemy and can NOT get my head around this code.
The first half I get, but the bottom items in bold I can not get it together.
The output is listed next to it and is valid code.
Can anyone explain the bottom 2 items and ’ checkPastLimit.bind(this,2)’ to me?
I can’t see the flow of how this moves through the code.
//
var arr1 = [1,2,3,4,5,6,7,8,9,10];
//
function mapForEach(arr, fn) {
var newArr = [];
for( i = 0; i < arr.length; i++) {
newArr.push(
fn(arr[i])
)
};
return newArr;
}
//
var arr2 = mapForEach(arr1, function(item) {
return item * 2
});
//
console.log(arr2); // output: (10) [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//
var checkPastLimit = function(limit, item) {
return item > limit;
}
//
var arr4 = mapForEach(arr1, checkPastLimit.bind(this,2));
console.log(arr4); // output: (10) [false, false, true, true, true, true, true, true, true, true]