๐Ÿค ์€์ง€log ๐Ÿค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ์ •์ˆ˜ ์ฐพ๊ธฐ ๋ณธ๋ฌธ

๐ŸŒˆ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ์ •์ˆ˜ ์ฐพ๊ธฐ

Eun_zii 2023. 12. 29. 10:31

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0

- ์ •์ˆ˜ ์ฐพ๊ธฐ

 

๐Ÿ’š ๋ฌธ์ œ์„ค๋ช…

  • ์ •์ˆ˜ ๋ฆฌ์ŠคํŠธ num_list์™€ ์ฐพ์œผ๋ ค๋Š” ์ •์ˆ˜ n์ด ์ฃผ์–ด์งˆ ๋•Œ, num_list์•ˆ์— n์ด ์žˆ์œผ๋ฉด 1์„ ์—†์œผ๋ฉด 0์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

 

๐Ÿ’š ์ œํ•œ์กฐ๊ฑด

  • 3 ≤ num_list์˜ ๊ธธ์ด ≤ 100
  • 1 ≤ num_list์˜ ์›์†Œ ≤ 100
  • 1 ≤ n ≤ 100

 

๐Ÿ’š ํ’€์ด

function solution(num_list, n) {
    if(num_list.includes(n)){
        return 1
    } else {
        return 0
    }
}

 

โœ… ๋ฐฐ์—ด/ ๋ฌธ์ž์—ด์— ํŠน์ • ๊ฐ’์ด ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€ ํŒ๋‹จํ•˜๋Š” includes() ์‚ฌ์šฉํ•ด์„œ 1 / 0์„ ๋ฆฌํ„ดํ•ด์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

 

๐Ÿ’ก includes() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด์˜ ํ•ญ๋ชฉ์— ํŠน์ • ๊ฐ’์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์ ์ ˆํžˆ true ๋˜๋Š” false๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

 

728x90