Created
June 18, 2018 00:55
-
-
Save charlesdarkwind/81d61e39de2ba8f8cec7d6b8eb3a6f0f to your computer and use it in GitHub Desktop.
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
const getAvgSpread = prices => { | |
let totalQty = 0, totalPrices = 0; | |
for (let price in prices) { | |
const qty = prices[price]; | |
totalQty += qty; | |
totalPrices += parseFloat(price) * qty; | |
} | |
const avgPrice = parseFloat((totalPrices / totalQty).toFixed(8)); | |
return { avgPrice, totalQty }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment