//CallBacks:
//===========
function fun(x) {
console.log(x);
x();
}
function innerFun() {
console.log('innerFun');
}
fun(innerFun);
// OUTPUT:
// ƒ innerFun() {
// console.log('innerFun');
// }
// innerFun
//-----------------------------------------------------------
// Array methods - map
//=====================
function square(num) {
return num * num;
}
let a = [1, 2, 3, 4, 5];
let b = a.map(square);
let c = a.map(function (n, idx) {
console.log(idx);
return n * n * n;
});
//OUTPUT:
//=======
// 0
// 1
// 2
// 3
// 4
console.log(b);
// OUTPUT:
// =======
// [1, 4, 9, 16, 25]
console.log(c);
// OUTPUT:
// =======
// [1, 8, 27, 64, 125]
//-----------------------------------------------------------------
// Array methods - filter method:
//===============================
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
function isOdd(num) {
if (num % 2 !== 0) {
return true;
}
return false;
}
let res = arr.filter(isOdd);
console.log(res);
// OUTPUT:
// =======
// [1, 3, 5, 7, 9]