Answers for "JS Recursive getLength of Array"

0

JS Recursive getLength of Array

function getLength(array) {
    return 0 in array ? 1 + getLength(array.slice(1)) : 0;
}

console.log(getLength([1]));             // 1
console.log(getLength([1, 2]));          // 2
console.log(getLength([1, 2, 3, 4, 5])); // 5
console.log(getLength([], 0));           // 0
Posted by: Guest on September-18-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language