从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 ]
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短