Hammurabi Markup

We examine the markup and capture digits for the expected keywords. Should report unmatched lines somehow.

function parse (text) { let result = {}, m for (let line of text.split(/\n/)) { if (m = line.match(/BUY (\d+)$/)) result.buy = m[1] if (m = line.match(/SELL (\d+)$/)) result.buy = -m[1] if (m = line.match(/FEED (\d+)$/)) result.feed = m[1] if (m = line.match(/PLANT (\d+)$/)) result.plant = m[1] } return result }

parse (` FEED 2000 PLANT 1000 SELL 20`)

http://js.ward.asia.wiki.org/assets/pages/snippet-template/basicjs.html?snippet-template HEIGHT 200