[3, 5, 4, 3, 6, 2, 3, 4].reduce((a, i) => a + i);
[3, 5, 4, 3, 6, 2, 3, 4].reduce((a, i) => a + i, 5 );
[3, 5, 4, 3, 6, 2, 3, 4].reduce(function(a, i){return (a + i)}, 0 );
[3, 5, 4, 3, 6, 2, 3, 4].reduce((a, i) => a * i);
[3, 5, 4, 3, 6, 2, 3, 4].reduce((a, i) => Math.max(a, i), -Infinity);
Math.max(...[3, 5, 4, 3, 6, 2, 3, 4]);
let data = [ ["The","red", "horse"],
["Plane","over","the","ocean"],
["Chocolate","ice","cream","is","awesome"],
["this","is","a","long","sentence"]
]
let dataConcat = data.map(item=>item.reduce((a,i)=>`${a} ${i}`))
['The red horse', 'Plane over the ocean', 'Chocolate ice cream is awesome', 'this is a long sentence']
let dupes = [1,2,3,'a','a','f',3,4,2,'d','d']
let withOutDupes = dupes.reduce((noDupes, curVal) => {
if (noDupes.indexOf(curVal) === -1) { noDupes.push(curVal) }
return noDupes
}, [])
let obj = [ {name: 'Alice', job: 'Data Analyst', country: 'AU'}, {name: 'Bob', job: 'Pilot', country: 'US'}, {name: 'Lewis', job: 'Pilot', country: 'US'}, {name: 'Karen', job: 'Software Eng', country: 'CA'}, {name: 'Jona', job: 'Painter', country: 'CA'}, {name: 'Jeremy', job: 'Artist', country: 'SP'}, ]
let ppl = obj.reduce((pre,curr)=>{
let newpre = curr['country']
if(!pre[newpre]){
pre[newpre]=[]
}
pre[newpre].push(curr)
return pre
},{})
let flattened = [[3, 4, 5], [2, 5, 3], [4, 5, 6]].reduce(
(singleArr, nextArray) => singleArr.concat(nextArray), [])
[ [3, 4, 5],
[2, 5, 3],
[4, 5, 6]
].flat();
[-3, 4, 7, 2, 4].reduce((acc, cur) => {
if (cur> 0) {
let R = cur**2;
acc.push(R);
}
return acc;
}, []);
[16, 49, 4, 144]
const reverseStr = str=>[...str].reduce((a,v)=>v+a)