Skip to content

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

re: 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."

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

code of conduct - report abuse