Created
June 5, 2012 15:01
-
-
Save pmcelhaney/2875523 to your computer and use it in GitHub Desktop.
map() is your friend
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
/* | |
map() is cool! | |
This function essentially loops over each row of a table and puts | |
its data in an array of objects. | |
It returns something like this: | |
[ | |
{rate: 1.0, apy: 1.0, productLabel: '3 month CD', earnings: 123.45}, | |
{rate: 1.12, apy: 1.13, productLabel: '6 month CD', earnings: 543.21}, | |
... | |
] | |
*/ | |
var rateData = myTable.find('tbody > tr').map(function () { | |
var tr = $(this); | |
return { | |
rate: extractNumber(tr.children('.rate').text()), | |
apy: extractNumber(tr.children('.apy').text()), | |
productLabel: tr.children('.term').text(), | |
earnings: extractNumber(tr.children('.earnings').text()) | |
}; | |
}); | |
var extractNumber = function (str) { | |
return parseFloat(str.replace(/[^0-9.]/g, "")); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment