- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Maximum decreasing adjacent elements in JavaScript
We are given an array of integers, and we are required to find the maximal absolute difference between any two of its adjacent elements.
For example: If the input array is −
const arr = [2, 4, 1, 0];
Then the output should be −
const output = 3;
because, the maximum absolute difference is in the elements 4 and 1.
Example
The code for this will be −
const arr = [2, 4, 1, 0]; const maximumDecreasing = (arr = []) => { const res = arr.slice(1).reduce((acc, val, ind) => { return Math.max(Math.abs(arr[ind] − val), acc); }, 0); return res; }; console.log(maximumDecreasing(arr));
Output
And the output in the console will be −
3
- Related Articles
- Maximum product of any two adjacent elements in JavaScript
- Maximum sum of difference of adjacent elements in C++
- JavaScript: Adjacent Elements Product Algorithm
- Maximum product of 4 adjacent elements in matrix in C++
- Maximum sum such that no two elements are adjacent in C++
- Maximum set bit sum in array without considering adjacent elements in C++
- Maximum Sum Decreasing Subsequence in C++
- Finding element greater than its adjacent elements in JavaScript
- Maximum sum such that no two elements are adjacent - Set 2 in C++
- Maximum sum in circular array such that no two elements are adjacent in C++
- Maximum sum such that no two elements are adjacent Alternate Method in C++ program
- Multiply Adjacent elements in Python
- Python – Adjacent elements in List
- Maximum length subarray with difference between adjacent elements as either 0 or 1 in C++
- Maximum length subsequence with difference between adjacent elements as either 0 or 1 in C++

Advertisements