0
Pls I need help on improving the performance of my code in terms of time and space complexity.
The code calculates the total annual income a man earns. But I would like this code to be rewritten with improved performance in mind. Pls I want solutions only in Javascript. Thanks a lot as you try to help out. https://code.sololearn.com/Wef90Pb81PGF/?ref=app
3 Answers
+ 1
okafor okwuchukwu charisma You can avoid the for loop if you do this:
const text = 'He earns 5000 euro from salary per\ month, 10000 euro annual bonus, 15000 euro\ online courses per month.';
const arr = text.match(/\d+/g);
const totalAnnualIncome = (+arr[0] + +arr[2]) * 12 + +arr[1];
console.log(totalAnnualIncome);
+ 1
Thanks a lot, you are always the first to help me out. I so much appreciate your kindness.
+ 1
okafor okwuchukwu charisma Thank you. That's very nice of you to say so. All the best with your learning.