Skip to content

Instantly share code, notes, and snippets.

@dfadler
Created September 18, 2015 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfadler/35a0748d990d09609d47 to your computer and use it in GitHub Desktop.
Save dfadler/35a0748d990d09609d47 to your computer and use it in GitHub Desktop.
Expressive Code
var a = [{
name:'fluffy',
age: 23,
run: function() {
// does something
}
}, {
name:'gunny',
age: 31,
run: function() {
// does something
}
}];
// Not very expressive
for(var i = 0, len = a.length; i < len; i++) {
if(a[i].name === 'gunny') {
a[i].run();
}
}
// More expressive
a.forEach(function(animal) {
if(animal.name === 'gunny') {
animal.run();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment