题解 | #判断斐波那契数组#
判断斐波那契数组
https://www.nowcoder.com/practice/9df2a366eb25495caff41612bd0ffca6
const _isFibonacci = (array) => {
// 判断长度是否合格
if (array.length < 3) return false;
// 当index索引值小于3时判断是否为最短且有效的斐波那契数列
// 当index索引值大于3时判断当前item值是否为前两项索引item项值的和
return array.every((item, index) =>
index < 3
? array[0] === 0 && array[1] === 1 && array[2] === 1
: item === array[index - 1] + array[index - 2]
);
};
睿联技术公司福利 62人发布
