gpt4 book ai didi

javascript - 有人可以将此箭头函数转换为普通函数吗?

转载 作者:行者123 更新时间:2023-11-30 07:49:24 26 4
gpt4 key购买 nike

<分区>

我无法将此箭头函数转换为普通函数。我已经在 chrome 的控制台面板中对此进行了测试。这段代码摘自freecodeCamp.org Es6课

//This is what I have tried. The final output result is showing undefined


const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = function(arr) {
"use strict";
const squaredIntegers = function(num) {
(function() {
arr.filter(Number.isInteger(num) && num > 0);
});
return squaredIntegers;
}
}

const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);

//Here is the Arrow function I was trying to convert

const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => {
"use strict";
const squaredIntegers = arr.filter(num => Number.isInteger(num) && num > 0);
return squaredIntegers;
};
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);


//The code should output this
[4, 42, 6];

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com