Created
August 9, 2017 04:35
-
-
Save jeffwesson/127f1d69d04df3250bdb5a631d22b5c6 to your computer and use it in GitHub Desktop.
Sums items in a baby registry on Buy Buy Baby
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
Array.prototype.slice.call(document.querySelectorAll('.productRow .productContainer .productContent')).reduce((a, item) => { | |
let o = {}; | |
o['requested'] = parseInt(item.querySelector('.requested').innerText.replace(/\D/g, '')); | |
o['purchased'] = parseInt(item.querySelector('.purchase').innerText.replace(/\D/g, '')); | |
o['price'] = parseFloat((item.querySelector('.rlpPrice') || item.querySelector('.toalpriceLtl')).innerText.replace(/[^\d\.]/g, '')); | |
a.push(o); | |
return a; | |
}, []).filter(item => item.requested !== item.purchased).reduce((s, item) => { | |
s += item.price * item.requested - item.purchased; | |
return s; | |
}, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment