본문 바로가기

알고리즘

JS 단어를 입력받아 짝수는 대문자, 홀수는 소문자로 변환

[문제] Write a function toWeirdCase (weirdcase in Ruby) that accepts a string, and returns the same string with all even indexed characters in each word upper cased, and all odd indexed characters in each word lower cased. The indexing just explained is zero based, so the zero-ith index is even, therefore that character should be upper cased.

 

The passed in string will only consist of alphabetical characters and spaces(' '). Spaces will only be present if there are multiple words. Words will be separated by a single space(' ').

 

Examples:

toWeirdCase( "String" );//=> returns "StRiNg"

toWeirdCase( "Weird string case" );//=> returns "WeIrD StRiNg CaSe"

 

 

map((x,i))   x는 배열 내 현재값, i는 배열내 현재 값의 index



출처: https://im-developer.tistory.com/36?category=831367 [Code Playground]