Code Monkey home page Code Monkey logo

algorithms's Introduction

algorithms

알고리즘, 코딩테스트 연습 레포지토리입니다.

algorithms's People

Contributors

icstuckyi avatar

Stargazers

Jiho Lee avatar

Watchers

 avatar

algorithms's Issues

[return문] 나머지가 1이 되는 수 찾기

문제 원본 링크
https://school.programmers.co.kr/learn/courses/30/lessons/87389
ec6ac40

의사코드 또는 나의 풀이

function solution(n) {
   for (let i = 2; i<n; i++){
       // n%i === 1 ? return i : null;
       if (n%i === 1) return i;
   }
}

문제가 되는 부분

  1. if문 이후의 return i; 는 왜 {}로 감싸주지 않아도 if문의 조건식 하에 작동하는가?
  2. return 문을 통과해서 for문을 탈출한다면,
    function solution(n){i}; 꼴이 되는 것이 아닌가? return 처리를 한번더 해줘야 하는게 아닌가?
  3. 주석처리한 삼항연산자는 왜 작동하지 않을까?

[스코프] 짝수의 합

문제 원본 링크
https://school.programmers.co.kr/learn/courses/30/lessons/120831
bb7f6a4

의사코드 또는 나의 풀이

function solution(n) {
    let a = 0;
    for (i=0; i<=n; i+=2) {
        a += i;
    }
    return a;
}

문제가 되는 부분
문제는 없었으나, 제어문 안의 조건문에 으레 작성하는 i에도 키워드(let, const)를 사용해 선언해줘야 안전하다고 한다.
image
출처: https://poiemaweb.com/js-scope

코드가 바르게 작성되었을 때 기대되는 동작
조건문 안의 i에 let이나 const 키워드를 작성하지 않으면 "암묵적 전역" 으로 동작하게 된다. 마치 var처럼 작동하게 되어 오염될 가능성이 있다.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.