It might help to add these console.logs so you can better understand the individual values
function uff(a) {
const validCharacters = "abcdefghijklmnopqrstuvwxyz".split("");
const stringCharacters = a
.toLowerCase()
.split("")
.reduce(
(characters, character) =>
validCharacters.indexOf(character) > -1
? characters.concat(character)
: characters,
[]
);
// I don`t understand how this strict equality is working. Why are these two values are equal?
console.log(`stringCharacters array: ${stringCharacters}`)
console.log(`stringCharacters string: ${stringCharacters.join("")}`)
console.log(`reverse of the stringCharacters array: ${stringCharacters.reverse()}`)
console.log(`reverse of the stringCharacters array turned back into a string: ${stringCharacters.reverse().join("")}`)
return stringCharacters.join("") === stringCharacters.reverse().join("");
}
uff("racecar")
Oh thanks
I have done it and now it is clear. May I have an other question
I understand that it checks stringcharacters against validcharacters. I don`t get the second half of the ternary operator ( : characters, ).
What does it send back? An empty array? Why is it not enough just characters or just the empty ?
Thanks