(javascript) Whale Talk

정세비·2021년 5월 18일
0

test

목록 보기
7/13
post-thumbnail

고래어 번역하기 (반복문 활용)

  • 규칙
    (1) 자음이 없으며 y를 제외한 모음만 있음
    (2) u와 e는 다른 모음보다 길기 때문에 2배로 늘려야 함
    (3) 고래어는 하나의 대문자 string 으로 출력되어야 함
    (4) 인간어 : Life is a sum of all our choices
let human = 'life is a sum of all our choices';
let vowle = ['a', 'e', 'i', 'o', 'u'];
let dolphin = [];

for (let i = 0; i < human.length; i++) {
  for (let j = 0; j < vowle.length; j++) {
    if (human[i] === vowle[j]) {
        if(human[i] === 'u') {
            dolphin.push('uu');
        } else if (human[i] === 'e') {
            dolphin.push('ee');
        } else {
            dolphin.push(human[i]);
        }
    }
  }
}

console.log(dolphin.join('').toUpperCase());


💡 출력값

IEEIAUUOAOUUOIEE

profile
파주

0개의 댓글