Zipcode Filter
Last active
September 5, 2016 16:15
-
-
Save erickeno/bf466f61371f3ad4bab6e07538dc378e to your computer and use it in GitHub Desktop.
Using filter to filter and return new object
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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
<div id="app"></div> | |
</body> | |
</html> |
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
import expect from 'expect' | |
var branches = {'06708': 'hello', '06709': 'goodbye'}; | |
var leads = [ | |
{ | |
name: 'steve', | |
zip: '06708' | |
}, | |
{ | |
name: 'stark', | |
zip: '06709' | |
}, | |
{ | |
name: 'tony', | |
zip: '06707' | |
} | |
]; | |
var myZip = leads.filter(function(row){ | |
var zip = row.zip; | |
if(branches[zip] == 'hello'){ | |
return row; | |
} | |
}); | |
document.getElementById('app').innerHTML = myZip[0].zip; | |
console.log(myZip); | |
expect(myZip.length).toBe(1); |
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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"expect": "1.20.1" | |
} | |
} |
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
'use strict'; | |
var _expect = require('expect'); | |
var _expect2 = _interopRequireDefault(_expect); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var branches = { '06708': 'hello', '06709': 'goodbye' }; | |
var leads = [{ | |
name: 'steve', | |
zip: '06708' | |
}, { | |
name: 'stark', | |
zip: '06709' | |
}, { | |
name: 'tony', | |
zip: '06707' | |
}]; | |
var myZip = leads.filter(function (row) { | |
var zip = row.zip; | |
if (branches[zip] == 'hello') { | |
return row; | |
} | |
}); | |
document.getElementById('app').innerHTML = myZip[0].zip; | |
console.log(myZip); | |
(0, _expect2.default)(myZip.length).toBe(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment