从JavaScript中的数字列表等于或大于数字
我们需要编写一个JavaScript函数,该函数将数字数组作为第一个参数,并将单个数字作为第二个参数。该函数应返回一个数组,其中包含输入数组中所有大于或等于作为第二个参数的数字的元素。
示例
以下是代码-
const arr = [56, 34, 2, 7, 76, 4, 45, 3, 3, 34, 23, 2, 56, 5];
const threshold = 40;
const findGreater = (arr, num) => {
const res = [];
for(let i = 0; i < arr.length; i++){
if(arr[i] < num){
continue;
};
res.push(arr[i]);
};
return res;
};
console.log(findGreater(arr, threshold));输出结果
这将在控制台中产生以下输出-
[ 56, 76, 45, 56 ]
热门推荐
5 初八祝福语简短语
10 成长仪式的简短祝福语
11 分手祝福语简短短句
12 参加婚礼祝福语大全简短
13 周末祝福语正能量简短
14 端午发给客户祝福语简短
15 爱情贺卡祝福语简短英语
16 直播生孩子祝福语简短
17 八十大寿简短祝福语
18 诗词文案祝福语简短精辟