코드로 우주평화

Abbreviate a Two Word Name 본문

나는 이렇게 학습한다/Algorithm & SQL

Abbreviate a Two Word Name

daco2020 2022. 3. 6. 13:39
반응형

Description:

Write a function to convert a name into initials. This kata strictly takes two words with one space in between them.

The output should be two capital letters with a dot separating them.

It should look like this:

Sam Harris => S.H

patrick feeney => P.F

 

solution:

1. Change the name to all uppercase letters.
2. Separate strings based on space and put them in an array.
3. Put the first letter of the words in the array into a temporary array.
4. The temporary array is returned as a string with a '.' delimiter.

 

 

function abbrevName(name){
  word_arr = name.toUpperCase().split(' ')
  let temp_arr = []
  for (let word of word_arr){
    temp_arr.push(word[0])
  }
  return temp_arr.join(".")
}

 

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Highest and Lowest  (0) 2022.03.08
Who likes it?  (0) 2022.03.07
Equal Sides Of An Array  (0) 2022.03.05
Is this a triangle?  (0) 2022.03.04
Sum of Numbers  (0) 2022.03.03