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 02585f5

Browse files
authored
BogoSort.js: Simplify Array.isSorted() and add doctests
As discussed at TheAlgorithms#164 (comment) Also related to add doctests as discussed in TheAlgorithms#142
1 parent 86b3622 commit 02585f5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

‎Sorts/BogoSort.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
* sorted in ascending order.
44
*/
55

6+
// > [].isSorted()
7+
// true
8+
// > [1].isSorted()
9+
// true
10+
// > [1,2,3].isSorted()
11+
// true
12+
// > [3,2,1].isSorted()
13+
// false
614
/* eslint no-extend-native: ["off", { "exceptions": ["Object"] }] */
715
Array.prototype.isSorted = function () {
816
const length = this.length
9-
10-
if (length < 2) {
11-
return true
12-
}
13-
1417
for (let i = 0; i < length - 1; i++) {
1518
if (this[i] > this[i + 1]) {
1619
return false

0 commit comments

Comments
(0)

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