📅  最后修改于: 2022-03-11 15:02:25.811000             🧑  作者: Mango
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