Last active
September 13, 2025 13:06
-
-
Save victorpolko/ffd1857f031f3aa47cb3ad934931bbcd to your computer and use it in GitHub Desktop.
JavaScript: get array length without `.length`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function arrLength(arr) { | |
| if (!arr || !arr[0]) return 0; | |
| const [_head, ...tail] = arr; | |
| return 1 + arrLength(tail); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment