import { bubbleSort } from '../algorithms/sorting-algorithms/bubble-sort' ; import { heapSort } from '../algorithms/sorting-algorithms/heap-sort' ; import { mergeSort } from '../algorithms/sorting-algorithms/merge-sort' ; import { quickSort } from '../algorithms/sorting-algorithms/quick-sort' ; import { SortingState } from '../store/sorting/state' ; import { AlgorithmType } from './types/app-types/algorithm-classes-types' ; import { ArrayStackType } from './types/sorting-types/array-stack-type' ; import { sortingALgorithms } from './types/sorting-types/consts' ; import { BUBBLE_SORT , HEAP_SORT , MERGE_SORT , QUICK_SORT , SortingAlgorithmsType , } from './types/sorting-types/sorting-alorithm-types' ; import { SortingAlgorithmResult } from './types/sorting-types/sorting-results-types' ; export const sortNameToSortType = ( name ) : SortingAlgorithmsType => { switch ( name ) { case 'Bubble Sort' : return BUBBLE_SORT ; case 'Quick Sort' : return QUICK_SORT ; case 'Merge Sort' : return MERGE_SORT ; case 'Heap Sort' : return HEAP_SORT ; default : return BUBBLE_SORT ; } } ; export const isSortingAlgorithm = ( alg ) : boolean => { return sortingALgorithms . some ( ( elem ) => elem === alg ) ; } ; export const getSorginAlgorithmOutput = ( alg , sortingState ) : SortingAlgorithmResult => { switch ( alg ) { case BUBBLE_SORT : { return { ... bubbleSort ( sortingState ) } ; } case MERGE_SORT : { return { ... mergeSort ( sortingState ) } ; } case QUICK_SORT : { return { ... quickSort ( sortingState ) } ; } case HEAP_SORT : { return { ... heapSort ( sortingState ) } ; } default : return { output : [ ] } ; } } ; export const copyNumbersImmutable = ( numbers ) : ArrayStackType [ ] => { return [ ... numbers . map ( ( elem ) => ( { ... elem } ) ) ] ; } ;