I decided I need to work on my code challenge skills so this week I am going to demonstrate how to make a javascript function that accepts and array as an argument and returns a string written in camel case. If you are wondering what camelcase is, it is the was words are separated by capital letters instead of with a space. ex..

thisIsWhatCamelCaseLooksLike

In this problem each value of the array that we are given is going to be an separate word, so for example it will look similar to this…

['HELLO', 'tHIs', 'sHoulD', 'be', 'camel', 'CASE']

Let’s think about how to approach the problem. In my opinion the first step should be to make a function that returns a capitalized word. Unfortunately in javascript there is no pre made function to capitalize a word ( like there is in ruby ) so we will have to .toLowerCase() each word, next remove the first letter of the word and .toUpperCase() it, and finally combine the capitalized letter with the rest of the lowercased word. Here is my solution for a capitalizer function…

  const capitalizer = (word) => {     const lowerCaseWord = word.toLowerCase()     const cappedLetter = lowerCaseWord[0].toUpperCase()     const result = cappedLetter + lowerCaseWord.slice(1)   return result}

Cool! It works perfectly. Now solving our camelcase problem will be a breeze! If we use map() on our array and use our capitalizer function function we will get

['Hello', 'This', 'Should', 'Be', 'Camel', 'Case']

with this all we have left to do is to take the first word in the array and .toLowerCase() it, then join(‘’) the rest of the array, and finally combine the two strings. Here is my solution…

const problem = (array) => {
const capitalizer = (word) => { const lowerCaseWord = word.toLowerCase() const cappedLetter = lowerCaseWord[0].toUpperCase() const result = cappedLetter + lowerCaseWord.slice(1) return result } const firstWord = array[0] const restOfArray = array.map(word => capitalizer(word)).slice(1).join("") const answer = firstWord + restOfArrayreturn answer}

Looks good! The function is working exactly as it should! When passed the array from earlier the function returns

'helloThisShouldBeCamelCase'