๐
First Element
First Element์ฌ์ ๋ฐฐ์ด +10pts
Problem
Write a function that returns the first element of an array.
Examples
Input:
first([1, 2, 3])Output:
1Explanation
์ด ๋ฌธ์ ๋ **๋ฐฐ์ด ์ธ๋ฑ์ฑ**์ ๊ธฐ์ด๋ฅผ ํ์ตํฉ๋๋ค. ๋ฐฐ์ด์ ์ฒซ ๋ฒ์งธ ์์์ ์ ๊ทผํ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์๋๋ค. **๋ฐฐ์ด ์ธ๋ฑ์ค** ๋ฐฐ์ด์ ์ธ๋ฑ์ค๋ 0๋ถํฐ ์์ํฉ๋๋ค: - arr[0]: ์ฒซ ๋ฒ์งธ ์์ - arr[1]: ๋ ๋ฒ์งธ ์์ - arr[arr.length - 1]: ๋ง์ง๋ง ์์ **์ฒซ ๋ฒ์งธ ์์ ์ ๊ทผ** `arr[0]`์ ๋ฐฐ์ด์ ์ฒซ ๋ฒ์งธ ์์๋ฅผ ๋ฐํํฉ๋๋ค. **๋น ๋ฐฐ์ด์ ๊ฒฝ์ฐ** ๋น ๋ฐฐ์ด์์ arr[0]์ undefined๋ฅผ ๋ฐํํฉ๋๋ค. **at() ๋ฉ์๋ (ES2022)** `arr.at(0)`๋ ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค. at...
View detailed explanation โKey Concepts
๋ฐฐ์ด ์ธ๋ฑ์ฑ 0-based ์ธ๋ฑ์ค ์์ ์ ๊ทผ undefined ๋ฐํ
Time: O(1) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.