2
Through that question: How to remove all element from array except the first one in javascript.
I adapted the code to 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 both counts head and tail.
I’ve never seen anything like: ([x, ...xs]) => x.
I know that the Spread along with arrow functions(arrow functions).
Doubt:
- Like a code like
([x, ...xs]) => xreturned only the first letter and([x, ...xs]) => xsreturned all the rest?
But allow me one comment: the title of the question addresses one issue and the content others.
– Sam
@Andersoncarloswoss that’s the Spread?
– Marconi
Spread, actually :D Yes, it is one of its uses
– Woss
About Arrow functions, see What is the difference between Function() {} and () => {}? Why doesn’t $http.get work? and What does the operator "=>" mean?
– bfavaretto
I won’t put it as an answer, because I don’t know the whole principle, but I’ll try to help with some information: Strings are strings, that is, they can be considered concatenated letter arrays. That’s the part I don’t know exactly how it works.
([x, ...xs]) => xbasically takes an array with undefined values, and returns only the first value,x. The same goes for the other, takes all the values that are not the first, thexs.– Máttheus Spoo