|
|
|
|
|
by foldr
834 days ago
|
|
I think that's true when it comes to functional programming in the large (designing systems without lots of implicit mutable state), but less so when it comes to the code style of individual functions. For example, one of the following functions is written in a 'functional' style and the other is not, but they are equally easy to unit test: function getLongNames(names) {
let longNames = [];
for (const n of names) {
if (n.length > 20)
longNames.push(n)
}
return longNames;
}
function getLongNames(names) { return names.filter(n => n.length > 20); }
In this case the second implementation is clearly superior, as it avoids implementing array filtering de novo. But the same point applies to other examples where neither style promotes more code reuse than the other. |
|