Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 1.29 KB

File metadata and controls

22 lines (16 loc) · 1.29 KB

__ Today I Leaned __ 2018.07.02. MON

  1. Algorithm (codewars) : string의 앞, 뒤 문자를 제거
    String.prototype 확인한 덕분에 삽질 방지.

    • String.prototype.substring(1, string.length - 1);
      Returns the characters in a string between two indexes into the string.
      첫번째 인덱스는 포함, 마지막 인덱스는 불포함
    • String.prototype.slice(1, -1);
      Extracts a section of a string and returns a new string.
      인덱스가 음의 정수일 경우, length 기준으로 계산
  2. Algorithm (codewasr) : Sum of odd numbers
    1 | 3 5 | 7 9 11 | 13 15 17 19 | 21 23 25 27 29 | ... : given
    1 | 2 | 3 | 4 | 5 | ... : parameter(index)
    1 | 8 | 27 | 64 | 125 |... : result
    난 index에 따라서 첫번째 값( n * (n - 1) + 1), 마지막 값 (start + 2 * (n - 1)) 구해서 계산했는데 그냥 세제곱하면 되는거였... (한숨)

    Math.pow(n, 3), 혹은 n ** 3
    알고리즘 계산 할 때, 원리도 원리지만 결과를 보고 과정을 간단하게 할 수 있으니, 결과를 보는 습관을 들이자!