Skip to content

Latest commit

 

History

History
executable file
·
29 lines (20 loc) · 430 Bytes

javascriptCodeGolf.md

File metadata and controls

executable file
·
29 lines (20 loc) · 430 Bytes

Swap numbers

[a, b] = [b, a];

Unique array values

let unique = [...new Set(array)];

Sum

array.reduce((accumulator, item) => accumulator + item.value, 0);

Max value of object property in array

Math.max(...array.map((object) => object[property]));

Longest string in an array

array.reduce((a, b) => (a.length > b.length ? a : b), "");