Skip to content

Commit

Permalink
✨ Feature(#46): 배열 비교 함수 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
rhehfl committed Nov 4, 2024
1 parent cd77c94 commit 358dd0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/pages/quiz/Quiz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ResultModal from '../../features/quiz/ui/ResultModal';
import getParams from '../../utils/getParams';
import TotalResults from '../../features/quiz/ui/TotalResults';
import { useState } from 'react';
import isArrayContentEqual from '../../utils/arraysEqual';
import isEqualArray from '../../utils/isEqualArray';
import { ResponseButton, SubmitSection } from '../../features/quiz/styles';
import QuizzesQuery from '../../queries/quizzesQuery';
import useMoadl from '../../hooks/useModal';
Expand Down Expand Up @@ -82,7 +82,7 @@ export default function Quiz() {
<ResponseButton
disabled={userResponseAnswer[0] === ''}
onClick={() => {
setResult(isArrayContentEqual(userResponseAnswer, answer));
setResult(isEqualArray(userResponseAnswer, answer));
openModal();
}}
>
Expand Down
9 changes: 6 additions & 3 deletions src/utils/arraysEqual.ts → src/utils/isEqualArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
*
* @returns boolean값
*
* @example isArrayContentEqual([1,2,3,4,5],['a',2,3,1]);
* @example isEqualArray([1,2,3,4,5],['a',2,3,1]);
* //false
*/
const isArrayContentEqual = (array1: any[], array2: any[]): boolean => {
const isEqualArray = <T>(
array1: T[] | readonly T[],
array2: T[] | readonly T[]
): boolean => {
if (array1.length !== array2.length) return false;
for (let i = 0; i < array1.length; i++) {
if (array1[i] !== array2[i]) {
Expand All @@ -19,4 +22,4 @@ const isArrayContentEqual = (array1: any[], array2: any[]): boolean => {
}
return true;
};
export default isArrayContentEqual;
export default isEqualArray;

0 comments on commit 358dd0a

Please sign in to comment.