☁️ goormTIL | 알고리즘 #33

매루·2025년 10월 28일

goormTIL

목록 보기
31/67
post-thumbnail

📅 2025-10-27

➡️ 알고리즘에 대해 새롭게 알게 된 것 또는 헷갈리는 부분 정리


🔎 학습 리마인드

📌 알고리즘이란?

  • 컴퓨터가 문제를 해결할 수 있도록 방법이나 절차를 자세히 설명하는 과정
  • 컴퓨터는 스스로 판단하지 못하고, 주어진 지시대로만 움직이기 때문에 컴퓨터가 효율적으로 동작할 수 있도록 명령을 내려야 함
  • 알고리즘은 문제를 해결하기 위한 구체적인 절차와 논리적인 사고 방식

📌 사전 지식

💡 Truthy, Falsy

falsy

  • false
  • null
  • undefined
  • 0
  • NaN
  • ''

truthy

  • 언급한 6가지 falsy값 외에 모든 값

💡 논리연산자

&& (AND 연산자)

  • 양쪽 다 truetrue

|| (OR 연산자)

  • 하나라도 truetrue

💡 문자열

숫자 ↔ 문자

  • String()
    let num = 123;
    console.log(num);            // 123
    console.log(typeof num);     // number
    
    let str = String(num);
    console.log(str);            // '123'
    console.log(typeof str);     // string
  • Number()
    let str = '123';
    console.log(str);            // '123'
    console.log(typeof str);     // string
    
    let num = Number(str);
    console.log(num);            // 123
    console.log(typeof num);     // number

문자열 합치기

  • + 연산자
    let str = 'a' + 'b';
    console.log(str); // 'ab'

문자의 탐색

  • for문 (인덱스 기반)
    let str = 'abcde';
    
    for (let i = 0; i < str.length; i++) {
      console.log(str[i]);
    }
  • for … of문 (값 기반)
    let str = 'abcde';
    
    for (const ch of str) {
      console.log(ch);
    }

0개의 댓글