Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c70f197

Browse files
Merge remote-tracking branch 'origin/fixing-JS-docs-for-Sorts-Folder' into fix-jsdocs
2 parents 5aa8bfa + 7560357 commit c70f197

File tree

8 files changed

+33
-3
lines changed

8 files changed

+33
-3
lines changed

‎Sorts/AlphaNumericalSort.js

Lines changed: 7 additions & 2 deletions
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

‎Sorts/BeadSort.js

Lines changed: 3 additions & 0 deletions
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.
11+
* @returns {number[]} Returns a sorted array of positive integers.
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 */

‎Sorts/BogoSort.js

Lines changed: 3 additions & 0 deletions
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 {String[]}
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[]}
1619
*/
1720
function shuffle(array) {
1821
for (let i = array.length - 1; i; i--) {

‎Sorts/BubbleSort.js

Lines changed: 4 additions & 0 deletions
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[]}
48+
* @returns {number[]} The sorted array.
4549
*/
4650
export function alternativeBubbleSort(arr) {
4751
let swapped = true

‎Sorts/CocktailShakerSort.js

Lines changed: 3 additions & 0 deletions
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[]}
12+
* @returns {number[]} The sorted array.
1013
*/
1114
export function cocktailShakerSort(items) {
1215
for (let i = items.length - 1; i > 0; i--) {

‎Sorts/CountingSort.js

Lines changed: 5 additions & 0 deletions
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) => {

‎Sorts/FindSecondLargestElement.js

Lines changed: 5 additions & 1 deletion
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

‎Sorts/FisherYatesShuffle.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @returns {Array} The shuffled array.
3+
*/
14
export const shuffle = (array) => {
25
let maxLength = array.length
36
let temp

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /