DEV Community

loading...
Cover image for Day 14 of JavaScriptmas - Maximal Adjacent Difference Solution

Day 14 of JavaScriptmas - Maximal Adjacent Difference Solution

Sekti
Keep moving forward. Learn well not learn fast.
・1 min read

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

Discussion (0)