Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing JSDOCS for Sorts Folder the folder that been modified are Alph… #1649

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Sorts/AlphaNumericalSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Sorts/BeadSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 using Bead Sort.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "using Bead Sort" is not helpful here or in the next line.

* @returns {number[]} Returns a sorted array of positive integers using Bead Sort.
* @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 */
Expand Down
3 changes: 3 additions & 0 deletions Sorts/BogoSort.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Checks whether the given array is sorted in ascending order.
* @param {number[]} array The array to be checked for sorted order.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

number[] is wrong. Any comparable objects are fine. (Strings would be fine as well, for example, though the order may not be what you expect.)

The comments are also a bit redundant. You're effectively stating the same thing three times.

* @returns {boolean} Returns true if the array is sorted in ascending order, false otherwise.
*/
export function isSorted(array) {
const length = array.length
Expand All @@ -13,6 +15,7 @@ export function isSorted(array) {

/**
* Shuffles the given array randomly in place.
* @param {any[]} array The array to be shuffled.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this comment help?

*/
function shuffle(array) {
for (let i = array.length - 1; i; i--) {
Expand Down
4 changes: 4 additions & 0 deletions Sorts/BubbleSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,6 +44,8 @@ export function bubbleSort(items) {

/**
* Using a while loop and a for loop.
* @param {number[]} arr The array to be sorted.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the array is sorted in-place.

* @returns {number[]} The sorted array.
*/
export function alternativeBubbleSort(arr) {
let swapped = true
Expand Down
3 changes: 3 additions & 0 deletions Sorts/CocktailShakerSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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[]} items The array of numbers to be sorted.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, please note that the sorting is in-place

* @returns {number[]} The sorted array.
*/
export function cocktailShakerSort(items) {
for (let i = items.length - 1; i > 0; i--) {
Expand Down
5 changes: 5 additions & 0 deletions Sorts/CountingSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 5 additions & 1 deletion Sorts/FindSecondLargestElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Sorts/FisherYatesShuffle.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Shuffles the elements of the given array randomly in place.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again you only really need one of the comments.

* @param {Array} array The array to be shuffled.
* @returns {Array} The shuffled array.
*/
export const shuffle = (array) => {
let maxLength = array.length
let temp
Expand Down
Loading