Through this question: How to remove all element from array except the first one in javascript .
I've adapted the code for my need.
var rua = 'RUA NILO PEÇANHA';
const head = ([x, ...xs]) => x
const tail = ([x, ...xs]) => xs
console.log('${head(rua).toUpperCase()}${tail(rua).join('').toLowerCase()}')
I ended up choosing the code that has the two covenants head
and tail
.
I've never seen anything like: ([x, ...xs]) => x
.
I know that Spread
is being used together with arrow functions ( arrow functions
).
Doubt:
- How did a code like
([x, ...xs]) => x
return only the first letter and([x, ...xs]) => xs
returned all the rest?