Skip to content

EASY SOLVED #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cdb16ad
findLargestElement.js Solved
krishvsoni Dec 5, 2023
212e7dc
Solved expenditure-analysis.js
krishvsoni Dec 5, 2023
e4d0bb3
anagram.js Solved
krishvsoni Dec 6, 2023
e7bae6b
Create README.md
krishvsoni Dec 6, 2023
f4ef87b
palindrome.js Solved
krishvsoni Dec 6, 2023
49d0523
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Dec 6, 2023
987e42c
countVowels.js Solved
krishvsoni Dec 6, 2023
cc05ce6
countVowels Solved
krishvsoni Dec 6, 2023
7d3b171
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Dec 7, 2023
5a48300
1.2 Assignment
krishvsoni Dec 7, 2023
08ede7c
Merge branch 'master' of https://github.com/krishvsoni/assignments
krishvsoni Dec 7, 2023
bdab009
findLargestElement.js Solved
krishvsoni Dec 7, 2023
aada93f
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Dec 11, 2023
fb83211
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Dec 14, 2023
f3fcfaf
Commit
krishvsoni Dec 14, 2023
6283578
async solved
krishvsoni Dec 14, 2023
01f3ca9
commit
krishvsoni Dec 15, 2023
09d3f1e
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Dec 19, 2023
c5008e2
01-middleweares
krishvsoni Dec 19, 2023
87f2d3f
02-jwt
krishvsoni Dec 19, 2023
4e26fc3
Update admin.js
krishvsoni Dec 20, 2023
7828d62
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Dec 23, 2023
fd5d0a9
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Dec 28, 2023
d2891da
db
krishvsoni Dec 29, 2023
62e3cd7
done
krishvsoni Dec 29, 2023
ae80fa6
commit
krishvsoni Dec 31, 2023
0da8545
TIckTick
krishvsoni Dec 31, 2023
1003847
commit
krishvsoni Dec 31, 2023
2ee036c
commit
krishvsoni Jan 7, 2024
9f149ce
commit
krishvsoni Jan 14, 2024
9e03122
commit
krishvsoni Jan 14, 2024
c13eb00
React
krishvsoni Jan 18, 2024
8112d9e
Bday
krishvsoni Jan 18, 2024
bcca8df
commit
krishvsoni Jan 20, 2024
7d9fd58
commit
krishvsoni Jan 20, 2024
faf3091
commit
krishvsoni Jan 20, 2024
5e3efa7
axious vs fetch
krishvsoni Feb 1, 2024
a089840
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Feb 1, 2024
9f3af2a
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Feb 7, 2024
17d84bb
Merge branch '100xdevs-cohort-2:master' into master
krishvsoni Mar 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Solved expenditure-analysis.js
  • Loading branch information
krishvsoni committed Dec 5, 2023
commit 212e7dcc4f3a7d160aecbede526961496eb22e66
22 changes: 21 additions & 1 deletion 01-js/easy/expenditure-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@
*/

function calculateTotalSpentByCategory(transactions) {
return [];
const categoryTotals = {};

transactions.forEach(transaction => {
const { category, price } = transaction;

if (!categoryTotals[category]) {
categoryTotals[category] = price;
} else {
categoryTotals[category] += price;
}
});

// Convert the object to an array of objects with the required format
const result = Object.entries(categoryTotals).map(([category, totalSpent]) => ({
category,
totalSpent,
}));

return result;
}

module.exports = calculateTotalSpentByCategory;