Created
March 5, 2015 01:30
-
-
Save EvanFreeman/4729fd02781084225a31 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/yicuvaxinu
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var stocks = [ | |
{ | |
symbol: 'xyz', | |
price: 1234, | |
order: 1 | |
}, | |
{ | |
symbol: 'xyx', | |
price: 12.00, | |
order: 1 | |
}, | |
{ | |
symbol: 'xyw', | |
price: 1543.00, | |
order: 2 | |
} | |
]; | |
Array.prototype.findWhere = function(projection) { | |
var result = []; | |
for (var i = 0; this.length > i; i++) { | |
if (projection(this[i])) { | |
result.push(this[i]); | |
} | |
} | |
return result; | |
}; | |
var result = stocks.findWhere(function(stock) { | |
return stock.price > 12; | |
}); | |
console.log(result); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var stocks = [ | |
{ | |
symbol: 'xyz', | |
price: 1234, | |
order: 1 | |
}, | |
{ | |
symbol: 'xyx', | |
price: 12.00, | |
order: 1 | |
}, | |
{ | |
symbol: 'xyw', | |
price: 1543.00, | |
order: 2 | |
} | |
]; | |
Array.prototype.findWhere = function(projection) { | |
var result = []; | |
for (var i = 0; this.length > i; i++) { | |
if (projection(this[i])) { | |
result.push(this[i]); | |
} | |
} | |
return result; | |
}; | |
var result = stocks.findWhere(function(stock) { | |
return stock.price > 12; | |
}); | |
console.log(result);</script></body> | |
</html> |
This file contains 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
var stocks = [ | |
{ | |
symbol: 'xyz', | |
price: 1234, | |
order: 1 | |
}, | |
{ | |
symbol: 'xyx', | |
price: 12.00, | |
order: 1 | |
}, | |
{ | |
symbol: 'xyw', | |
price: 1543.00, | |
order: 2 | |
} | |
]; | |
Array.prototype.findWhere = function(projection) { | |
var result = []; | |
for (var i = 0; this.length > i; i++) { | |
if (projection(this[i])) { | |
result.push(this[i]); | |
} | |
} | |
return result; | |
}; | |
var result = stocks.findWhere(function(stock) { | |
return stock.price > 12; | |
}); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment