Skip to content

Commit

Permalink
refactor(Queue): isValid 메서드 내부 로직 getDepositActionCount로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
Jong1co committed Apr 27, 2024
1 parent 6cf749b commit a9fa54d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/service/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class BankAccountServiceQueueImpl implements BankAccountServiceQueue {
private queue: Array<BankAccountQueueNode> = [];
private isExec: boolean = false;

isValid = () => {
const depositActionCountMap = this.queue.reduce((accr, curr) => {
private getDepositActionCount = (queue: Array<BankAccountQueueNode>) => {
return queue.reduce((accr, curr) => {
if (curr.action !== "deposit") return accr;

if (accr[curr.id]) {
Expand All @@ -31,6 +31,10 @@ export class BankAccountServiceQueueImpl implements BankAccountServiceQueue {

return accr;
}, {} as Record<number, number>);
};

isValid = () => {
const depositActionCountMap = this.getDepositActionCount(this.queue);

const isInvalidAction = Object.values(depositActionCountMap).some(
(count) => count > 1
Expand Down

0 comments on commit a9fa54d

Please sign in to comment.