python-vs-javascript
python-vs-javascript copied to clipboard
Make the JS part of Zip example less verbose
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 👍