code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

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:13:56+05:18, updated 2019-11-30T02:16:17+05:18 · History · Edit