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