Hello,
Following this exercice:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs
I increase the difficultie by adding one space character at the end of the string.
But my solution for delete this space doesn’t work and I don’t understand why.
function urlSlug(title) {
let titleLower = title.toLowerCase().split("");
let courante = [];
for (let i = 0; i < titleLower.length; i++) {
if (titleLower[0] == " ") {
delete titleLower[0];
}
else if (titleLower[i] == " " && courante[courante.length-1] == " "){
delete titleLower[i]
} else {
courante.push(titleLower[i]);
}
}
let newTitle = courante.join('').split(" ")
console.log(newTitle)
for (let i = 0; i < newTitle.length; i++) {
if (newTitle[newTitle.length-1] == " ") {
newTitle.pop();
}
}
console.log(newTitle.join("-"))
}
urlSlug(" Winter Is Coming ")
// Only change code above this line
The result of console.log:

[ ‘winter’, ‘is’, ‘coming’, ‘’ ]
winter-is-coming-
When I test this litle code with VScode, console.log display one table with length = 3, thus without ‘’ :
let newTitle = [ 'winter', 'is', 'coming', '' ];
for (let i = 0; i < newTitle.length; i++) {
if (newTitle[newTitle.length-1] == " ") {
newTitle.pop();
}
console.log(newTitle)