tidyCheckbook = checkbook => { sum = 0; rules = checkbook.split("\n"); rules[0] = `Original_balance: ${rules[0]}`; amountOfRules = rules.length-1; return rules .map(rule => { rule = rule.replace(/[;?!{},]/g, "").split(" "); return rule = { id: rule[0], category: rule[1], checkAmount: parseFloat(rule[2]).toFixed(2)} }) .sort((a, b) => a.id - b.id) .map(rule => { return (`${rule.id} ${rule.category} ${isNaN(rule.checkAmount) ? '':rule.checkAmount}`)}) .join("\n") .concat(`\n======================\nTotal expense: ${sum}\nAverage expense: ${sum / amountOfRules}` ) }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: Daily Challenge #4 - Checkbook Balancing
For further actions, you may consider blocking this person and/or reporting abuse