diff --git a/Sorts/AlphaNumericalSort.js b/Sorts/AlphaNumericalSort.js index fb6be8f424..9387bc0d78 100644 --- a/Sorts/AlphaNumericalSort.js +++ b/Sorts/AlphaNumericalSort.js @@ -17,9 +17,14 @@ 2. z11 P.S. use this function, as there are a lot of implementations on the stackoverflow and other forums, but many of them don't work correctly (can't pass all my tests) - + */ - +/** + * @param {string} a The first string to compare. + * @param {string} b The second string to compare. + * @returns {number} Returns a number indicating whether the first string comes before, after, or is the same as the second string in sort order. + * -1 if a comes before b, 1 if a comes after b, and 0 if they are the same. + */ const alphaNumericalSort = (a, b) => { /* https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare diff --git a/Sorts/BeadSort.js b/Sorts/BeadSort.js index 6a6f69398d..f4de1ac766 100644 --- a/Sorts/BeadSort.js +++ b/Sorts/BeadSort.js @@ -7,6 +7,9 @@ * NOTE: It only works for arrays of positive integers. * * Wikipedia: https://en.wikipedia.org/wiki/Bead_sort + * @param {number[]} sequence An array of positive integers to be sorted. + * @returns {number[]} Returns a sorted array of positive integers. + * @throws {RangeError} Throws a RangeError if the input sequence contains any negative integers. */ export function beadSort(sequence) { /* Let's ensure our sequence has only Positive Integers */ diff --git a/Sorts/BogoSort.js b/Sorts/BogoSort.js index eeb4f7feeb..313cacb591 100644 --- a/Sorts/BogoSort.js +++ b/Sorts/BogoSort.js @@ -1,5 +1,7 @@ /** * Checks whether the given array is sorted in ascending order. + * @param {String[]} + * @returns {boolean} Returns true if the array is sorted in ascending order, false otherwise. */ export function isSorted(array) { const length = array.length @@ -13,6 +15,7 @@ export function isSorted(array) { /** * Shuffles the given array randomly in place. + * @param {any[]} */ function shuffle(array) { for (let i = array.length - 1; i; i--) { diff --git a/Sorts/BubbleSort.js b/Sorts/BubbleSort.js index 5571fac047..40e9c2cb6e 100644 --- a/Sorts/BubbleSort.js +++ b/Sorts/BubbleSort.js @@ -15,6 +15,8 @@ /** * Using 2 for loops. + * @param {number[]} items The array to be sorted. + * @returns {number[]} The sorted array. */ export function bubbleSort(items) { const length = items.length @@ -42,6 +44,8 @@ export function bubbleSort(items) { /** * Using a while loop and a for loop. + * @param {number[]} + * @returns {number[]} The sorted array. */ export function alternativeBubbleSort(arr) { let swapped = true diff --git a/Sorts/CocktailShakerSort.js b/Sorts/CocktailShakerSort.js index 033c7c461a..2079b6753c 100644 --- a/Sorts/CocktailShakerSort.js +++ b/Sorts/CocktailShakerSort.js @@ -7,6 +7,9 @@ * * Wikipedia (Cocktail Shaker Sort): https://en.wikipedia.org/wiki/Cocktail_shaker_sort * Wikipedia (Bubble Sort): https://en.wikipedia.org/wiki/Bubble_sort + * + * @param {number[]} + * @returns {number[]} The sorted array. */ export function cocktailShakerSort(items) { for (let i = items.length - 1; i > 0; i--) { diff --git a/Sorts/CountingSort.js b/Sorts/CountingSort.js index c7d495d92f..1a2e54a408 100644 --- a/Sorts/CountingSort.js +++ b/Sorts/CountingSort.js @@ -6,6 +6,11 @@ * * Wikipedia: https://en.wikipedia.org/wiki/Counting_sort * Animated Visual: https://www.cs.usfca.edu/~galles/visualization/CountingSort.html + * + * @param {number[]} arr The array to be sorted. + * @param {number} min The minimum value in the array. + * @param {number} max The maximum value in the array. + * @returns {number[]} The sorted array. */ export const countingSort = (arr, min, max) => { diff --git a/Sorts/FindSecondLargestElement.js b/Sorts/FindSecondLargestElement.js index 504b7e1192..b7174085da 100644 --- a/Sorts/FindSecondLargestElement.js +++ b/Sorts/FindSecondLargestElement.js @@ -8,7 +8,11 @@ * Resources: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set */ - +/** + * Finds the second largest element in an array of numbers while filtering out duplicate values. + * @param {number[]} array The array of numbers. + * @returns {number} The second largest element in the array. + */ const secondLargestElement = (array) => { const largestElement = Math.max(...array) let element = -Number.MAX_VALUE diff --git a/Sorts/FisherYatesShuffle.js b/Sorts/FisherYatesShuffle.js index 214cb5baa7..d892ff1449 100644 --- a/Sorts/FisherYatesShuffle.js +++ b/Sorts/FisherYatesShuffle.js @@ -1,3 +1,6 @@ +/** + * @returns {Array} The shuffled array. + */ export const shuffle = (array) => { let maxLength = array.length let temp