DEV Community

Cover image for Day 14 of JavaScriptmas - Maximal Adjacent Difference Solution
Sekti Wicaksono
Sekti Wicaksono

Posted on

Day 14 of JavaScriptmas - Maximal Adjacent Difference Solution

Day 14 is finding the highest adjacent difference.

If a given array [2,4,1,0] will has the highest adjacent difference is 3.
If a given array [2,9,1,0] will has the highest adjacent difference is 8

This is JavaScript solution

function arrayMaximalAdjacentDifference(nums) {
    return Math.max(...nums.map((a,b) => Math.abs(a-b)));
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

DevCycle image

Fast, Flexible Releases with OpenFeature Built-in

Ship faster on the first feature management platform with OpenFeature built-in to all of our open source SDKs.

Start shipping