i have been facing coding issue while trying to reduce the data stream. Below is the sample code
Data is being filtered on the base of exchanges, now i need to filter out the pairs not given in pair array.
//data stream
var dataStream = {
"Coinbase": { "pairs": { "ETH": ["USD", "GBP", "BTC"], "DAI": ["USDC"], "LTC": ["GBP", "BTC", "USD", "EUR"], "ETC": ["EUR", "BTC", "USD"] } },
"Binance": { "pairs": { "ETH": ["USD", "BTC"], "DAI": ["USDC"], "LTC": ["GBP", "BTC"], "ETC": ["EUR"] } },
"CoinCorner": { "pairs": { "BTC": ["GBP", "EUR","LTC"] } }
};
//allowed exchages
var exchanges = ["Coinbase", "Binance", "Bitstamp"];
//allowed pairs
var pair = ["BTC","ETH","LTC"];
const filtered = Object.keys(dataStream)
.filter(key => exchanges.includes(key))
.reduce((obj, key) => {
obj[key] = dataStream[key].pairs;//do some reduction
return obj;
}, {});
console.log("data filtered:" + JSON.stringify(filtered));
I needed to reduce the result on the base of 'pair' array where including pairs only get to the object.
Update Result must be
var dataStream = {
"Coinbase": { "pairs": { "ETH": ["USD", "GBP", "BTC"], "LTC": ["GBP", "BTC", "USD", "EUR"] } },
"Binance": { "pairs": { "ETH": ["USD", "BTC"], "LTC": ["GBP", "BTC"]} }
};
If someone can help or give clue, i will be thankful. Thanks for your time.