milltest/main.js
2020-08-12 00:29:04 +01:00

27 lines
948 B
JavaScript

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);
observeMarket(market);
};
function buyerFunctions(product, quantity, buyer){
console.log(`The best price for ${product} is ${buyer.getBestPrice(product)}`) ;
console.log(`To completely fill a order of ${quantity} ${product} costs ${buyer.fillWithBestPrices(product,quantity)}`) ;
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();