
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Strictly increasing or decreasing array - JavaScript
In Mathematics, a strictly increasing function is that function in which the value to be plotted always increase. Similarly, a strictly decreasing function is that function in which the value to be plotted always decrease.
We are required to write a JavaScript function that takes in an array of numbers and returns true if it’s either strictly increasing or strictly decreasing, otherwise returns false.
Example
Following is the code −
const arr = [12, 45, 6, 4, 23, 23, 21, 1]; const arr2 = [12, 45, 67, 89, 123, 144, 2656, 5657]; const sameSlope = (a, b, c) => (b - a < 0 && c - b < 0) || (b - a > 0 && c - b > 0); const increasingOrDecreasing = (arr = []) => { if(arr.length <= 2){ return true; }; for(let i = 1; i < arr.length - 1; i++){ if(sameSlope(arr[i-1], arr[i], arr[i+1])){ continue; }; return false; }; return true; }; console.log(increasingOrDecreasing(arr)); console.log(increasingOrDecreasing(arr2));
Output
Following is the output in the console −
false true
- Related Articles
- Program to check whether list is strictly increasing or strictly decreasing in Python
- Strictly increasing sequence JavaScript
- Three strictly increasing numbers (consecutive or non-consecutive). in an array in JavaScript
- Make Array Strictly Increasing in C++
- Program to find length of longest strictly increasing then decreasing sublist in Python
- Find an element in an array such that elements form a strictly decreasing and increasing sequence in Python
- Longest subarray which only contains strictly increasing numbers JavaScript
- Convert to Strictly increasing integer array with minimum changes in C++
- Program to check right rotation forms increasing or decreasing array with first n natural numbers or not in Python
- Count Strictly Increasing Subarrays in C++
- Print array elements in alternatively increasing and decreasing order in C++
- Find the count of Strictly decreasing Subarrays in C++
- A strictly increasing linked list in Python
- Find Maximum Sum Strictly Increasing Subarray in C++
- Check if list is strictly increasing in Python

Advertisements