- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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