📚

First Element

First Element
쉬움 배열 +10pts

Problem

Write a function that returns the first element of an array.

Examples

Input: first([1, 2, 3])
Output: 1

Explanation

이 문제는 **배열 인덱싱**의 기초를 학습합니다. 배열의 첫 번째 요소에 접근하는 방법을 배웁니다. **배열 인덱스** 배열의 인덱스는 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.