code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

02 Pairwise Array Comparisons

/**
 * 
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

function pairwiseArrayComparisons(array) {
  let maxDelta = Math.abs(array[0] - array[1])
  for (let index = 0; index < array.length; index++) {
    const delta = Math.abs(array[index] - array[index + 1]);
    if(delta > maxDelta){
      maxDelta = delta
    }
  }
  return maxDelta
}

test('pairwise Array Comparisons', () => {
  expect(pairwiseArrayComparisons([70, 72, 68, 65, 74, 74, 73])).toEqual(9)
});

Created 2019-11-29T03:25:56+05:30, updated 2019-11-30T02:28:17+05:30 · History · Edit