// Currying :
//- Currying is an advanced technique of working with functions.
function sum(a) {
return function (b) {
return function (c) {
return function (d) {
console.log("sun is:::", a + b + c + d);
};
};
};
}
sum(5)(7)(3)(20);
function frankenSplice(arr1, arr2, n) {
// It's alive. It's alive!
let localArray = arr2.slice();
for (let i = 0; i < arr1.length; i++) {
localArray.splice(n, 0, arr1[i]);
n++;
}
return localArray;
}
// Reduce in javascript advance
// output: { '22': 2, '24': 2, '26': 1 }
const user = [
{name:"Abhishek",age:24},
{name:"Dhruval",age:22},
{name:"Anish",age:26},
{name:"Aakash",age:22},
{name:"Darshil",age:24},
]
const newUser = user.reduce((acc,cur)=>{
if(acc[cur.age]){
acc[cur.age] = acc[cur.age] +1
}
else{
acc[cur.age] = 1
}
return acc;
},{})
console.log(newUser)
function frankenSplice(arr1, arr2, n) {
// It's alive. It's alive!
let localArr = arr2.slice();
localArr.splice(n, 0, ...arr1);
return localArr;
}