240501

๋ฌธ์ œ : ๋‘ ์ •์ˆ˜ ์‚ฌ์ด์˜ ํ•ฉ ๋‚œ์ด๋„ : Lv.1 ์„ค๋ช… :

๋‘ ์ •์ˆ˜ a, b๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ a์™€ b ์‚ฌ์ด์— ์†ํ•œ ๋ชจ๋“  ์ •์ˆ˜์˜ ํ•ฉ์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. ์˜ˆ๋ฅผ ๋“ค์–ด a = 3, b = 5์ธ ๊ฒฝ์šฐ, 3 + 4 + 5 = 12์ด๋ฏ€๋กœ 12๋ฅผ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค.

์ œํ•œ์‚ฌํ•ญ

  • a์™€ b๊ฐ€ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ๋‘˜ ์ค‘ ์•„๋ฌด ์ˆ˜๋‚˜ ๋ฆฌํ„ดํ•˜์„ธ์š”.

  • a์™€ b๋Š” -10,000,000 ์ด์ƒ 10,000,000 ์ดํ•˜์ธ ์ •์ˆ˜์ž…๋‹ˆ๋‹ค.

  • a์™€ b์˜ ๋Œ€์†Œ๊ด€๊ณ„๋Š” ์ •ํ•ด์ ธ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

ํ’€์ด

function solution(a, b) {
    var answer = 0;
    if(a < b || a === b) {
        for(let i = a; i <= b; i++) {
            answer += i
        }
    } else if(a > b) {
         for(let i = b; i <= a; i++) {
            answer += i
        }
    }

    return answer;
}

๐Ÿ‘€ ๋‹ค๋ฅธ ์‚ฌ๋žŒ ํ’€์ด

function adder(a, b, s = 0){
  for (var i = Math.min(a, b); i <= Math.max(a, b); i++) s += i;
  return s;
}

๋ฌธ์ œ : ํ•ธ๋“œํฐ ๋ฒˆํ˜ธ ๊ฐ€๋ฆฌ๊ธฐ ๋‚œ์ด๋„ : Lv.1 ์„ค๋ช… :

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ชจ๋ฐ”์ผ์€ ๊ฐœ์ธ์ •๋ณด ๋ณดํ˜ธ๋ฅผ ์œ„ํ•ด ๊ณ ์ง€์„œ๋ฅผ ๋ณด๋‚ผ ๋•Œ ๊ณ ๊ฐ๋“ค์˜ ์ „ํ™”๋ฒˆํ˜ธ์˜ ์ผ๋ถ€๋ฅผ ๊ฐ€๋ฆฝ๋‹ˆ๋‹ค. ์ „ํ™”๋ฒˆํ˜ธ๊ฐ€ ๋ฌธ์ž์—ด phone_number๋กœ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ „ํ™”๋ฒˆํ˜ธ์˜ ๋’ท 4์ž๋ฆฌ๋ฅผ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ์ˆซ์ž๋ฅผ ์ „๋ถ€ *์œผ๋กœ ๊ฐ€๋ฆฐ ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ์‚ฌํ•ญ

  • aphone_number๋Š” ๊ธธ์ด 4 ์ด์ƒ, 20์ดํ•˜์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.

ํ’€์ด

function solution(phone_number) {
    let num = phone_number.slice(-4)
    let star = new Array(phone_number.length-4).fill('*').join('')
    
    return star+num
}

๐Ÿ‘€ ๋‹ค๋ฅธ ์‚ฌ๋žŒ ํ’€์ด

function hide_numbers(s){
  return s.replace(/\d(?=\d{4})/g, "*");
}

Last updated