Skip to content

Instantly share code, notes, and snippets.

@frontenddeveloping
Last active August 29, 2015 13:57
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 frontenddeveloping/9893164 to your computer and use it in GitHub Desktop.
Save frontenddeveloping/9893164 to your computer and use it in GitHub Desktop.
Array.prototype.mergeAsNumber example
Array.prototype.mergeAsNumber = function (array) {
var sortFunction = function (a,b) {return a-b},
commonArray = this.concat(array).sort(sortFunction),
element,
suchNumberAnotherIndex;
for (var i = 0, l = commonArray.length; i<l; i++) {
element = commonArray[i];
suchNumberAnotherIndex = commonArray.indexOf(element, i+1);
while (suchNumberAnotherIndex > -1) {
delete commonArray[suchNumberAnotherIndex];
i++;
suchNumberAnotherIndex = commonArray.indexOf(element, i);
}
}
return commonArray.sort(sortFunction);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment