4 ms·
I'd far rather save that for an alternative switch expression with pattern matching. const slowSum = (lst: {x: number}[]) => switch(list) { [
by hajile 4y ago
I'd far rather save that for an alternative switch expression with pattern matching.
const slowSum = (lst: {x: number}[]) =>
switch(list) {
[{x}, ...y] -> x + slowSum(y) //not tail recursive
[{x}, {x: y}] -> x + y //alias second x to y
[{x}] -> x //handle length 1
[] -> 0 //handle length 0
}
- tracker1 4y agoHaving been watching, and a couple times playing with Rust... would definitely like a similar pattern matching system in JS. I still feel the C# syntax for this feels a bit alien `varname switch {...}`.