Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a function variableNameify(words) that takes in an array of words. The function should return a string representing the //variable name obtained by combining the words and captitalizing them in mixCased style.
- function variableNameify(words){
- let newWordArray = [];
- newWordArray.push(words[0].toLowerCase())
- for(let i = 1; i < words.length; i++){
- let currentWord = words[i];
- currentWord = currentWord.toLowerCase();
- let firstLetter = currentWord.charAt(0);
- let firstLetterCap = firstLetter.toUpperCase();
- let remainingLetters = currentWord.slice(1);
- let capitalizedWord = firstLetterCap + remainingLetters;
- newWordArray.push(capitalizedWord);
- }
- newWordArray = newWordArray.join("");
- return newWordArray;
- }
- console.log(variableNameify(['is', 'prime'])) // => 'isPrime'
- console.log(variableNameify(['remove', 'last', 'vowel'])) // => 'removeLastVowel'
Advertisement
Add Comment
Please, Sign In to add comment