npx standard --fix

This commit is contained in:
cclauss
2020-05-03 09:05:12 +02:00
parent e62ad2f73e
commit 856dc2f63c
47 changed files with 2240 additions and 2371 deletions

View File

@ -3,53 +3,49 @@
* sorted in ascending order.
*/
Array.prototype.isSorted = function () {
const length = this.length
let length = this.length;
if (length < 2) {
return true
}
if (length < 2) {
return true;
for (let i = 0; i < length - 1; i++) {
if (this[i] > this[i + 1]) {
return false
}
for (let i = 0; i < length - 1; i++) {
if (this[i] > this[i + 1]) {
return false;
}
}
return true;
};
}
return true
}
/*
* A simple helper function to shuffle the array randomly in place.
*/
Array.prototype.shuffle = function () {
for (let i = this.length - 1; i; i--) {
let m = Math.floor(Math.random() * i);
let n = this[i - 1];
this[i - 1] = this[m];
this[m] = n;
}
};
for (let i = this.length - 1; i; i--) {
const m = Math.floor(Math.random() * i)
const n = this[i - 1]
this[i - 1] = this[m]
this[m] = n
}
}
/*
* Implementation of the bogosort algorithm. This sorting algorithm randomly
* rearranges the array until it is sorted.
* For more information see: https://en.wikipedia.org/wiki/Bogosort
*/
function bogoSort(items) {
while (!items.isSorted()) {
items.shuffle()
}
return items;
function bogoSort (items) {
while (!items.isSorted()) {
items.shuffle()
}
return items
}
//Implementation of bogoSort
// Implementation of bogoSort
var ar = [5, 6, 7, 8, 1, 2, 12, 14];
//Array before Sort
console.log(ar);
bogoSort(ar);
//Array after sort
console.log(ar);
var ar = [5, 6, 7, 8, 1, 2, 12, 14]
// Array before Sort
console.log(ar)
bogoSort(ar)
// Array after sort
console.log(ar)