From fcbd9cf56c565bd5f7bfea5c683acb3aa88e568b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 18 Mar 2024 01:16:01 +0100 Subject: [javascript] Implement the selling loop of the contracting automation --- nodejs/lib/utils.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'nodejs/lib/utils.js') diff --git a/nodejs/lib/utils.js b/nodejs/lib/utils.js index 1d2e451..a2c8128 100644 --- a/nodejs/lib/utils.js +++ b/nodejs/lib/utils.js @@ -1,3 +1,18 @@ +// cargo is a ship.cargo object, want is an optional symbol +export function categorizeCargo(cargo, want) { + const wanted = cargo.inventory.filter(i => i.symbol === want || i.symbol === 'ANTIMATTER'); + const goods = cargo.inventory.filter(i => i.symbol !== want && i.symbol !== 'ANTIMATTER'); + const wobj = wanted.reduce(function(acc, e) { + acc[e.symbol] = e.units; + return acc; + }, {}); + const gobj = goods.reduce(function(acc, e) { + acc[e.symbol] = e.units; + return acc; + }, {}); + return {wanted: wobj, goods: gobj}; +} + export function systemFromWaypoint(waypoint) { return waypoint.split('-').slice(0,2).join('-'); } -- cgit v1.2.3