mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
fixed a leak and added the let-statement
This commit is contained in:
@ -4,13 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
Array.prototype.isSorted = function() {
|
Array.prototype.isSorted = function() {
|
||||||
|
|
||||||
var length = this.length;
|
let length = this.length;
|
||||||
|
|
||||||
if (length < 2) {
|
if (length < 2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < length - 1; i++) {
|
for (let i = 0; i < length - 1; i++) {
|
||||||
if (this[i] > this[i + 1]) {
|
if (this[i] > this[i + 1]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -23,9 +23,9 @@ Array.prototype.isSorted = function() {
|
|||||||
*/
|
*/
|
||||||
Array.prototype.shuffle = function() {
|
Array.prototype.shuffle = function() {
|
||||||
|
|
||||||
for (var i = this.length; i; i--) {
|
for (let i = this.length -1; i; i--) {
|
||||||
var m = Math.floor(Math.random() * i);
|
let m = Math.floor(Math.random() * i);
|
||||||
var n = this[i - 1];
|
let n = this[i - 1];
|
||||||
this[i - 1] = this[m];
|
this[i - 1] = this[m];
|
||||||
this[m] = n;
|
this[m] = n;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user