Passionate about solving problems since 2012! I'm a full stack web developer with experience in AWS, TypeScript and React. Looking for new opportunities!
constcheckbook=`
1233.00
125 Hardware;! 24.8?;
123 Flowers 93.5
127 Meat 120.90
120 Picture 34.00
124 Gasoline 11.00
123 Photos;! 71.4?;
122 Picture 93.5
132 Tires;! 19.00,?;
129 Stamps 13.6
129 Fruits{} 17.6
129 Market;! 128.00?;
121 Gasoline;! 13.6?;
`.trim()// this will remove spaces, tabs, and breaklines \n at the beginning and end// Math.round doesn't round to X number of digits so I'm using this hacky methodconstround=value=>Math.round(value*100)/100// skip all non A-Za-z0-9\s\. caracters, globally, multiline, and case insensitiveconstcleanedCheckBook=checkbook.replace(/[^A-Za-z0-9\s\.]/gmi,'')// make an array where every element is a lineconstlines=cleanedCheckBook.split("\n")// extract the first element and save the value in floatconstoriginalBalance=parseFloat(lines.shift())lettotalExpenses=0constexpenses=[]// for the average// go thru each line and change itconstlinesProcessed=lines.map(line=>{const[number,category,expense]=line.split('')constexpenseFloat=parseFloat(expense)totalExpenses+=expenseFloatexpenses.push(expenseFloat)constcurrentBalance=originalBalance-totalExpensesreturn`${number}${category}${round(expense)} Balance ${round(currentBalance)}`}).join("\n")constaverageSpent=expenses.reduce((total,sum)=>total+sum)/expenses.lengthconsole.log(`
Original_Balance: ${round(originalBalance)}${linesProcessed}
Total Expenses: ${round(totalExpenses)}
Average spent: ${round(averageSpent)}
`)
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.
Here's my attempt:
My attempt with comments: