2 ms·
destructing is very useful and encourage good coding styles Is it? Personally I'd say that was bad code. What so wrong with using the original objects? Puttin
by mattmanser 10y ago
destructing is very useful and encourage good coding styles
Is it? Personally I'd say that was bad code. What so wrong with using the original objects?
Putting aside the need to variable swap once a year or so, all the other examples look really confusing to me and unclear what they're doing. The `Deep Matching` especially.
- fnord123 10y agovar lst = [[1,2], [3,4], [5,6]]; for (var [a,b] of lst) { console.log(a + b); } You could write a `zip` function to merge multiple iterables together and iterator them. Or use something like `.enumerate()` to yield indices along with the values.
- rubber_duck 10y ago>Is it? Yes, but not in the silly example showed. Consider something like : zip(fooArray, barArray, bazArray).map(([foo, bar, baz]) => foo + bar + baz) zip(fooArray, barArray, bazArray).map((arr) => arr[0] + arr[1] + arr[2]);
- ubertaco 10y agoIt's really nice for when you have to do operations where you want a "tuple" in Javascript. Consider the case of finding all companies along with their hires from the last week, but only if the company has a hire from the last week: companies.map(c => [c, employeeStorage.getEmployees(c)]) .map(([company, employees]) => [company, employees.filter(e => e.hireDate > aWeekAgo)]) .filter(([company, employees]) => employees.length > 0)