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

01 Highest And Lowest Weather

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

function getHighestAndLowestWeather(array) {
  let lowest = array[0]
  let highest = array[0]
  for (let i = 0; i < array.length; i++) {
    if (array[i] > highest) {
      highest = array[i]
    }
    if (array[i] < lowest) {
      lowest = array[i]
    }
  }
  return { lowest, highest }
}

test('weekly Weather', () => {
  expect(getHighestAndLowestWeather([2, 10, 40, 30, 1, 33])).toEqual({ lowest: 1, highest: 40 })
})

Created 2019-11-29T03:13:56+05:18, updated 2019-11-30T02:16:17+05:18 · History · Edit