Skip to content
loading...

re: There's no "else if" in JS VIEW POST

TOP OF THREAD FULL DISCUSSION
re: I've never heard that. What's the rationale?
 

In FP you could use filter instead of if, which makes your code more modular than stacking if on if.

In FP you could use filter instead of if

“In FP” preamble looks redundant here. All modern languages (save for, maybe, Malbolge,) allow filtering over stacked ifs.

The point I wanted to make was, "if you choose to do FP in your PL of choice you would use filter instead of if"

Unlike Haskell, JavaScript is not a purely functional language. Functions such as filter are recent additions to the language. If you look at the V8 source code for the filter function, you'll see this comment: "The following functions cannot be made efficient on sparse arrays while preserving the semantics."

github.com/v8/v8/blob/73c9be9b31d2...

That’s mostly not a matter of efficiency, it’s all about clean code.

code of conduct - report abuse