3 ms·
``` var dividers = { 2: function divideBy2 (lhs, unused) { return lhs >> 1 }, 4: function divideBy4 (lhs, unused) { return lhs >> 2 }, undefin
by tjallingt 9y ago
```
var dividers = {
2: function divideBy2 (lhs, unused) {
return lhs >> 1
},
4: function divideBy4 (lhs, unused) {
return lhs >> 2
},
undefined: function divideByNumber (lhs, rhs) {
return lhs / rhs
}
}
```
Does this actually work? I tried it out in the Chrome Debugger and it didn't work. It looks like the author is confusing it with Rusts match statement.
- idbehold 9y agoIt works just fine in Chrome's DevTools. > dividers[2](6) 3 > dividers[undefined](6, 3) 2
- rndgermandude 9y agoThe code uses dividers[divisor] so dividers[3](6, 3) so undefined(6,3) and that does not work
- idbehold 9y agoOh, yeah the divideSomeNumbers() function doesn't work correctly. It should probably be using: var divider = dividers[divisor] || dividers[undefined];