+ 2

[Solved]What's the way to get the sum of all salaries in the object?

https://code.sololearn.com/W85HRw2fqUbz/?ref=app

27th Jun 2022, 10:10 PM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
9 odpowiedzi
+ 3
Recursion for the save. @Ipang, I was of the same mind. https://code.sololearn.com/WgHj8b1zrMEE/?ref=app
28th Jun 2022, 2:55 AM
ODLNT
ODLNT - avatar
+ 2
I managed to collect and sum employees' salary and group the results by division using recursion. https://code.sololearn.com/Wef7hk53KxKA/?ref=app
28th Jun 2022, 2:30 AM
Ipang
+ 2
Thank you all for the contribution, recursion saves the day, I need to go learn it and how to use it.
28th Jun 2022, 5:03 AM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
+ 1
Justice check the code now, I provided pseudocode
27th Jun 2022, 10:23 PM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
+ 1
Jay Matthews it does gives me the result, but I want something that loops through all and give me a single result
27th Jun 2022, 10:42 PM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
+ 1
Muhammad Awwal Yusuf I believe because you're mixing several different data structures, it's not really feasible. Nesting data structures in different orders and level amounts is going to require you to use more loops to get what you want. I will say though that you can just use one result variable instead of having multiple for the different job types. You want to preserve the space you have since you're using memory hungry data structures. And each new variable you create takes up more space.
28th Jun 2022, 2:04 AM
Justice
Justice - avatar
0
Do you have an attempt where have tried already? It can be just pseudocode as well.
27th Jun 2022, 10:12 PM
Justice
Justice - avatar
0
I could only get into each of the object keys 'salary' . Let me edit the code so you see
27th Jun 2022, 10:14 PM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
0
Sure let us know when you do. Also, just as a tip, but you might want to put your code in a Node.js code bit rather than a web, since you're focusing solely on Javascript.
27th Jun 2022, 10:22 PM
Justice
Justice - avatar