Skip to content

Commit 18edde7

Browse files
committed
fixing JSDOCS for Sorts Folder the folder that been modified are AlphaNumerical,BeadSort,BogoSort,BubbleSort,CocktailShakerSort,CountinfSort,FindSecondsLargestElementSort,FisherYatesShuffle
1 parent bd34e9f commit 18edde7

8 files changed

+35
-3
lines changed

Diff for: Sorts/AlphaNumericalSort.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
2. z11
1818
1919
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)
20-
20+
2121
*/
22-
22+
/**
23+
* @param {string} a The first string to compare.
24+
* @param {string} b The second string to compare.
25+
* @returns {number} Returns a number indicating whether the first string comes before, after, or is the same as the second string in sort order.
26+
* -1 if a comes before b, 1 if a comes after b, and 0 if they are the same.
27+
*/
2328
const alphaNumericalSort = (a, b) => {
2429
/*
2530
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare

Diff for: Sorts/BeadSort.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* NOTE: It only works for arrays of positive integers.
88
*
99
* Wikipedia: https://en.wikipedia.org/wiki/Bead_sort
10+
* @param {number[]} sequence An array of positive integers to be sorted using Bead Sort.
11+
* @returns {number[]} Returns a sorted array of positive integers using Bead Sort.
12+
* @throws {RangeError} Throws a RangeError if the input sequence contains any negative integers.
1013
*/
1114
export function beadSort(sequence) {
1215
/* Let's ensure our sequence has only Positive Integers */

Diff for: Sorts/BogoSort.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/**
22
* Checks whether the given array is sorted in ascending order.
3+
* @param {number[]} array The array to be checked for sorted order.
4+
* @returns {boolean} Returns true if the array is sorted in ascending order, false otherwise.
35
*/
46
export function isSorted(array) {
57
const length = array.length
@@ -13,6 +15,7 @@ export function isSorted(array) {
1315

1416
/**
1517
* Shuffles the given array randomly in place.
18+
* @param {any[]} array The array to be shuffled.
1619
*/
1720
function shuffle(array) {
1821
for (let i = array.length - 1; i; i--) {

Diff for: Sorts/BubbleSort.js

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* Using 2 for loops.
18+
* @param {number[]} items The array to be sorted.
19+
* @returns {number[]} The sorted array.
1820
*/
1921
export function bubbleSort(items) {
2022
const length = items.length
@@ -42,6 +44,8 @@ export function bubbleSort(items) {
4244

4345
/**
4446
* Using a while loop and a for loop.
47+
* @param {number[]} arr The array to be sorted.
48+
* @returns {number[]} The sorted array.
4549
*/
4650
export function alternativeBubbleSort(arr) {
4751
let swapped = true

Diff for: Sorts/CocktailShakerSort.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*
88
* Wikipedia (Cocktail Shaker Sort): https://en.wikipedia.org/wiki/Cocktail_shaker_sort
99
* Wikipedia (Bubble Sort): https://en.wikipedia.org/wiki/Bubble_sort
10+
*
11+
* @param {number[]} items The array of numbers to be sorted.
12+
* @returns {number[]} The sorted array.
1013
*/
1114
export function cocktailShakerSort(items) {
1215
for (let i = items.length - 1; i > 0; i--) {

Diff for: Sorts/CountingSort.js

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*
77
* Wikipedia: https://en.wikipedia.org/wiki/Counting_sort
88
* Animated Visual: https://www.cs.usfca.edu/~galles/visualization/CountingSort.html
9+
*
10+
* @param {number[]} arr The array to be sorted.
11+
* @param {number} min The minimum value in the array.
12+
* @param {number} max The maximum value in the array.
13+
* @returns {number[]} The sorted array.
914
*/
1015

1116
export const countingSort = (arr, min, max) => {

Diff for: Sorts/FindSecondLargestElement.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
* Resources:
99
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
1010
*/
11-
11+
/**
12+
* Finds the second largest element in an array of numbers while filtering out duplicate values.
13+
* @param {number[]} array The array of numbers.
14+
* @returns {number} The second largest element in the array.
15+
*/
1216
const secondLargestElement = (array) => {
1317
const largestElement = Math.max(...array)
1418
let element = -Number.MAX_VALUE

Diff for: Sorts/FisherYatesShuffle.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Shuffles the elements of the given array randomly in place.
3+
* @param {Array} array The array to be shuffled.
4+
* @returns {Array} The shuffled array.
5+
*/
16
export const shuffle = (array) => {
27
let maxLength = array.length
38
let temp

0 commit comments

Comments
 (0)