Skip to content

Commit 62d97d2

Browse files
committed
Fix: Small bug with merge sort
1 parent 9b7d86a commit 62d97d2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/components/visualizers/MergesortVisualizer.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { VisualizerProps } from '../../interfaces';
66

77
export const MergeSortVisualizer: React.FC<VisualizerProps> = ({
88
array,
9+
arraySize,
910
setArray,
1011
setIsSorting,
1112
sortRef,
@@ -16,8 +17,8 @@ export const MergeSortVisualizer: React.FC<VisualizerProps> = ({
1617
const tl = gsap.timeline(); // todo: find better way than using global gsap timeline element
1718

1819
useEffect(() => {
19-
sortRef.current = () => startSort();
20-
}, [sortRef]);
20+
sortRef.current = (array: number[]) => startSort(array);
21+
}, [sortRef, array, arraySize]);
2122

2223
const mergeSort = async (array: number[], left = 0): Promise<number[]> => {
2324
if (array.length <= 1) {
@@ -118,7 +119,7 @@ export const MergeSortVisualizer: React.FC<VisualizerProps> = ({
118119
},
119120
);
120121

121-
const startSort = async () => {
122+
const startSort = async (array: number[]) => {
122123
setIsSorting(true);
123124
const sortedArray = await mergeSort([...array]);
124125
setArray(sortedArray);

0 commit comments

Comments
 (0)