Skip to content

Instantly share code, notes, and snippets.

@EvanFreeman
Created March 5, 2015 01:30
Show Gist options
  • Save EvanFreeman/4729fd02781084225a31 to your computer and use it in GitHub Desktop.
Save EvanFreeman/4729fd02781084225a31 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/yicuvaxinu
<!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>
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