Created
March 14, 2018 01:26
-
-
Save hperrin/22a6fce74c5d15f80cbf397fe2a2100a to your computer and use it in GitHub Desktop.
insertInOrder JavaScript Array method. (Insert item into a sorted array.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.insertInOrder = function(item) { | |
for (var i = 0; this[i] < item && i < this.length; i++); | |
this.splice(i, 0, item); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment