 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Longest subarray which only contains strictly increasing numbers JavaScript
We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument.
The function should then return the length of the longest continuous subarray from the array that only contains elements in a strictly increasing order.
A strictly increasing sequence is the one in which any succeeding element is greater than all its preceding elements.
Example
const arr = [5, 7, 8, 12, 4, 56, 6, 54, 89]; const findLongest = (arr) => {    if(arr.length == 0) {       return 0;    };    let max = 0;    let count = 0;    for(let i = 1; i < arr.length; i++) {       if(arr[i] > arr[i-1]) {          count++; }       else {          count = 0;       }       if(count > max) {          max = count;       }    }    return max + 1; }; console.log(findLongest(arr));  Output
And the output in the console will be −
4
Advertisements
 