- Related Questions & Answers
- How to get the smallest integer greater than or equal to a number in JavaScript?
- Select equal or nearest greater number from table in MySQL
- Python - Number of values greater than K in list
- JavaScript: Finding nearest prime number greater or equal to sum of digits - JavaScript
- Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold in C++
- Python Indices of numbers greater than K
- How to find numbers in an array that are greater than, less than, or equal to a value in java?
- Numbers smaller than the current number JavaScript
- How to get the largest integer less than or equal to a number in JavaScript?
- JavaScript - Find the smallest n digit number or greater
- Delete all the nodes from the list that are greater than x in C++
- How to represent X-axis label of a bar plot with greater than equal to or less than equal to sign using ggplot2 in R?
- Adding elements of an array until every element becomes greater than or equal to k in C++.
- Find all factorial numbers less than or equal to n in C++
- Print all prime numbers less than or equal to N in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return an array of all the elements from the input array that are greater than or equal to the number taken as the second argument.

Following is the code −

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));

This will produce the following output in console −

[ 56, 76, 45, 56 ]

Advertisements