python-vs-javascript icon indicating copy to clipboard operation
python-vs-javascript copied to clipboard

Make the JS part of Zip example less verbose

Open EddiG opened this issue 7 years ago • 0 comments

Currently, the example of JS looks more verbose than the Python

const list1 = [1, 3, 5]
const list2 = [2, 4, 6]

// [[1, 2], [3, 4], [5, 6]]
const zippedList = list1.map((x, y) => {
  return [x, list2[y]]
})

zippedList.forEach(element => {
  console.log(`${element[0]} ${element[1]}`)
})

I'm suggesting another version

const list1 = [1, 3, 5]
const list2 = [2, 4, 6]

// [[1, 2], [3, 4], [5, 6]]
list1
  .map((x, y) => [x, list2[y]])
  .forEach(([x, y]) => console.log(`${x} ${y}`))

Hope it will be helpfull. Thanks for your work 👍

EddiG avatar Sep 17 '18 11:09 EddiG