从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 ]
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短