DEV Community

Discussion on: Stop using for loops, here are other cool options

Collapse
 
aminnairi profile image
Amin • Edited

Thanks for your article! I too really like those cool little Array.prototype methods.

May I suggest another name for the FilterFn function, which is upper-camel-cased. Usually we write functions following the lower-camel-case conventions.

Of course this is non-blocking when writing code but if you are going on the readability path, you may want to convert this code and use this convention for your function names!

Another thing I noticed is the name of the function itself. I guess isModuloTwo is more self-explanatory than FilterFn since you may want to re-use this function elsewhere in your code.

Finally, suffixing all your functions with Fn is overkill. If you follow the above convention and some others, you'll easily identify functions, classes, constants, etc...

"use strict";

const isModuloTwo = number => number % 2 === 0;

const evens = [1, 2, 3, 4, 5].filter(isModuloTwo);

console.log(evens); // [2, 4]
Collapse
 
itismadhavan profile image
Madhavan Nagarajan

I totally agree your point. It is very important to name the functions right to express the intention of the function. In fact that is my next piece of topic I'm writing. watch out for that :)