by jeswin · 11y ago · 0 comments
/* 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]
Keep in mind this also comes up in cases like:
foo, _, bar = something()
In general you can't avoid doing something like it, why "optimize" for this one special case?Even worse:
let [a, b, c, d] = [2];
a receives 2. b, c, and d receive undefined.