Created
May 24, 2018 13:14
-
-
Save pbzona/5363d93e85e5c8965c7e7024be6833c5 to your computer and use it in GitHub Desktop.
anonymous functions example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "normal" way of writing (uses an anonymous function) | |
words.filter(function(word) { | |
return word.length < 6; | |
}); | |
// arrow function (uses an anonymous function) | |
words.filter(word => word.length < 6); | |
// but you don't have to use an anonymous function... | |
// filter takes a function as an argument, and you can define that separately | |
// to reuse it other places, or make your code more readable | |
function checkIfShorterThanSixChars(n) { | |
return n.length < 6; | |
}; | |
words.filter(checkIfShorterThanSixChars(word)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment