Hello! Can you help me with this? I need to get from a tale of glass to a Tale of Glass I don’t know why this doesn’t work, can you explain me why? I thought that with for each I can modify the original arr but here I feel like the array is the same as at the beginning.
the code:
class Formatter {
//add static methods here
static capitalize(str){
let cap = str.charAt(0).toUpperCase();
str = str.slice(1);
return cap+str;
}
static sanitize(str){
return str.replace(/[^\w'\-\s]/g, '')
}
//'the', 'a', 'an', 'but', 'of', 'and', 'for', 'at', 'by', and 'from'
static titleize(str){
let arr= str.split(" ")
arr.forEach( word=> { console.log(word)
if(word!=='the'||word!=="a"||word!=='but'||word!=="of"||word!=='and'||word!=="for"||word!=='at'||word!=="by"||word!=="from"){
console.log("if")
console.log(Formatter.capitalize(word))
word = Formatter.capitalize(word)
}
})
console.log("arr", arr)
let newStr= arr.join(" ")
// console.log(newStr)
return newStr
}
}
Formatter.titleize("a tale of two cities")