๐
Array Includes
Array Includes์ฌ์ ๋ฐฐ์ด +10pts
Problem
Write a function that checks if an array includes a specific value.
Examples
Input:
includes([1, 2, 3], 2)Output:
trueInput:
includes([1, 2, 3], 5)Output:
falseExplanation
์ด ๋ฌธ์ ๋ **includes ๋ฉ์๋**๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐฐ์ด์ ํน์ ๊ฐ์ด ํฌํจ๋์ด ์๋์ง ํ์ธํ๋ ๋ฐฉ๋ฒ์ ํ์ตํฉ๋๋ค. **includes() ๋ฉ์๋** ๋ฐฐ์ด์ ํน์ ์์๊ฐ ํฌํจ๋์ด ์์ผ๋ฉด true, ์์ผ๋ฉด false๋ฅผ ๋ฐํํฉ๋๋ค. **์ฌ์ฉ ์์** - [1, 2, 3].includes(2) โ true - [1, 2, 3].includes(5) โ false **indexOf์์ ๋น๊ต** - includes: ๋ถ๋ฆฌ์ธ ๋ฐํ (์กด์ฌ ์ฌ๋ถ๋ง ํ์ธ) - indexOf: ์ธ๋ฑ์ค ๋ฐํ (์์น๋ ์ ์ ์์, ์์ผ๋ฉด -1) **NaN ์ฒ๋ฆฌ*...
View detailed explanation โKey Concepts
includes ๋ฉ์๋ ๋ฐฐ์ด ๊ฒ์ ๋ถ๋ฆฌ์ธ ๋ฐํ NaN ์ฒ๋ฆฌ
Time: O(n) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.