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)