Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Checking if all array values are smaller than a limit using JavaScript
Problem
We are required to write a JavaScript function that takes in an array of numbers and a number. We should return true if all the numbers in the array are smaller than the number given as second argument, false otherwise.
Example
Following is the code −
const arr = [5, 34, 23, 14, 78, 45, 78];
const limit = 99;
const checkEvery = (arr = [], limit = 1) => {
const allSmaller = arr.every(el => {
return el < limit;
});
return allSmaller;
};
console.log(checkEvery(arr, limit));
Output
true
Advertisements
