Last active
April 8, 2019 11:33
-
-
Save alexnault/865013bfe06a8c24138093ac42a29e34 to your computer and use it in GitHub Desktop.
Declarative pattern example in JavaScript
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
const names = ["Han", "Chewbacca", "Luke", "Leia"]; | |
// imperative | |
const shortNames = []; | |
for (let i = 0; i < names.length; i++) { | |
if (names[i].length < 5) { | |
shortNames.push(names[i]); | |
} | |
} | |
// declarative | |
const shortNames = names.filter(name => name.length < 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment