We're a place where coders share, stay up-to-date and grow their careers.
First & Fast & Last try with JS
capitalizeFirstLast = sentence => { var arrWords = sentence.toLocaleLowerCase().split(" "); var newArrWords = []; arrWords.forEach((x,i)=> { var wordLength = x.length; if(wordLength > 2){ newArrWords.push(x.charAt(0).toUpperCase() + x.substr(1,wordLength-2) + x.charAt(wordLength - 1).toUpperCase()); } else{ newArrWords.push(x.toUpperCase()); } }); return newArrWords.join(" "); }
First & Fast & Last try with JS