본문 바로가기
알고리즘

Daily Coding 02. computeWhenDouble

by 디디 ( DD ) 2023. 1. 23.

Q. 연이율(number 타입, %)을 입력받아 원금이 2배 이상이 될 때까지 걸리는 시간(number 타입, 년)을 리턴해야 합니다.

 

 

function computeWhenDouble(interestRate) {
  let rate = 1 + interestRate/100;
  let result = 1;  //원금
  let year = 0;
  while(result < 2){  //원금의 두 배가 되기 전까지
    result = result * rate; 
    year++  //연수를 일 년씩 더해
  }
  return year;
}

 

 

 

 

 

'알고리즘' 카테고리의 다른 글

Daily Coding 06. letterCapitalize  (0) 2023.01.25
Daily Coding 05. firstReverse  (0) 2023.01.25
Daily Coding 04. firstCharacter  (0) 2023.01.24
Daily Coding 03. powerOfTwo  (0) 2023.01.24
Daily Coding 01. transformFirstAndLast  (0) 2023.01.23

댓글