Just playing around with the spread operator and I found a neat little design pattern I think I am going to work in:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
let testArr = [9,1, 2, 6, 3, 4]; const newMax = (arr) => { if(arr.length === 1) { return console.log('end')}; var [a, ...arr] = arr; let max = Math.max(a,...arr); console.log(max ,' >=', ...arr); newMax(arr); } newMax(testArr); //output 9 ' >=' 1 2 6 3 4 6 ' >=' 2 6 3 4 6 ' >=' 6 3 4 6 ' >=' 3 4 4 ' >=' 4 end |
Seems a fun way to look for edges like in the water trap toy problem? I am not sure, but it will be fun to play around with it.
Another thing that used to annoy me was how you had to use string concatenation. It just looked so ugly. I finally (okay I am late to the party) started using backticks for multi-line parties!
1 2 3 4 5 6 7 8 |
var motion = `Le mouvement de lacet sur la berge des chutes du fleuve, Le gouffre à l’étambot, La célérité de la rampe, L’énorme passade du courant Mènent par les lumières inouïes Et la nouveauté chimique Le voyageurs entourés des trombes du val Et du strom.` |
And finally a little more fun with the spread operator (thanks Alex Rauschmayer) but you can make an array only contain unique values in a very clean, native way.
1 2 3 4 |
const arr = [7, 3, 1, 3, 3, 7]; [...new Set(arr)] //returns [ 7, 3, 1 ] |