by gcb0 · 11y ago · 0 comments
like php's list/map but with several levels.
those are just asking for bugs that are hard to spot even on code reviews.
The main thing that bothers me is that the default behaviour is too permissive.
let a = [1,2,3,4,5];
let [b] = a; // ok. b receives 1
The equivalent Python will fail because there are "too many values to unpack." /* I can write code independent of getCheapestSellers() impl */
var [bestPrice, secondBest] = getCheapestSellers("product_name"); [bestPrice, secondBest, _*] = getCheapestSellers('product_name')Add: To clarify, the error shows up at runtime in Python. So you're going to need tests anyway. Just as in JS.
Btw (unrelated), you can do the same thing in JS as well [a, b, ...rest] = [1, 2, 3, 4, 5]
Even worse:
let [a, b, c, d] = [2];
a receives 2. b, c, and d receive undefined.