Skip to content

Instantly share code, notes, and snippets.

@hperrin
Created March 14, 2018 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hperrin/22a6fce74c5d15f80cbf397fe2a2100a to your computer and use it in GitHub Desktop.
Save hperrin/22a6fce74c5d15f80cbf397fe2a2100a to your computer and use it in GitHub Desktop.
insertInOrder JavaScript Array method. (Insert item into a sorted array.)
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