Skip to content

Commit

Permalink
refactor: getMatchCount 함수에 reduce 활용
Browse files Browse the repository at this point in the history
  • Loading branch information
365kim committed Apr 18, 2021
1 parent 30b056d commit 1ee3b01
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/components/containers/UserResult/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ export const getNumOfMatch = (lotto, winningNumber) => {
};

export const getMatchCount = (lottoBundle, winningNumber) => {
const matchCount = {};
return lottoBundle.reduce((acc, cur) => {
const numOfMatch = getNumOfMatch(cur, winningNumber);

lottoBundle.forEach((lotto) => {
const numOfMatch = getNumOfMatch(lotto, winningNumber);

matchCount[numOfMatch] = matchCount[numOfMatch] === undefined ? 1 : matchCount[numOfMatch] + 1;
});

return matchCount;
acc[numOfMatch] = acc[numOfMatch] + 1 || 1;
return acc;
}, {});
};

export const getStatistics = (lottoBundle, matchCount) => {
Expand Down

0 comments on commit 1ee3b01

Please sign in to comment.