数字数组是否相等-JavaScript
我们需要编写一个JavaScript函数,该函数接受两个Numbers数组,例如first和second,并检查它们的相等性。
如果-
它们包含相同的元素,并且顺序相同。
第一阵列和第二阵列的所有元素的乘积相等。
第一个数字数组-
const first = [3, 5, 6, 7, 7];
第二个数字数组-
const second = [7, 5, 3, 7, 6];
示例
以下是代码-
const first = [3, 5, 6, 7, 7];
const second = [7, 5, 3, 7, 6];
const isEqual = (first, second) => {
const prodFirst = first.reduce((acc, val) => acc*val);
const prodSecond = second.reduce((acc, val) => acc*val);
if(prodFirst === prodSecond){
return true;
};
for(let i = 0; i < firstCopy.length; i++){
if(first[i] === second[1]){
continue;
};
return false;
};
return true;
};
console.log(isEqual(first, second));输出结果
这将在控制台中产生以下输出-
true
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志