milltest/main.js

27 lines
948 B
JavaScript
Raw Normal View History

2020-08-11 11:55:43 +00:00
const {asda,costco,budgens} = require("./marketplace");
const {Market} = require("./Market");
const { Buyer } = require("./Buyer");
function main(){
const market = new Market([asda,budgens,costco]);
let buyer = new Buyer(market);
let product = "Apples";
let quantity = 10;
buyerFunctions(product, quantity, buyer);
2020-08-11 23:29:04 +00:00
observeMarket(market);
2020-08-11 11:55:43 +00:00
};
function buyerFunctions(product, quantity, buyer){
console.log(`The best price for ${product} is ${buyer.getBestPrice(product)}`) ;
2020-08-11 23:29:04 +00:00
console.log(`To completely fill a order of ${quantity} ${product} costs ${buyer.fillWithBestPrices(product,quantity)}`) ;
2020-08-11 11:55:43 +00:00
console.log(`To buy as quickly as possible ${quantity} ${product} costs ${buyer.quicklyFill(product,quantity)}`) ;
}
function observeMarket(market){
market.observable.subscribe( (mkt) => {
console.log(`The current price of apples are ${market.sellers[0].inventory["Apples"].price}`)});
}
main();