Last active
November 19, 2016 11:49
-
-
Save bferronato/f7f526d5d6bee1366619398cc5577357 to your computer and use it in GitHub Desktop.
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
/** | |
* Torna os elementos de um array unico, incrementando os que forem iguais | |
*/ | |
Array.prototype.oneOfAKind = function() { | |
for(var i = 1; i < this.length; i++) { | |
if(this[i-1] >= this[i]) { | |
this[i] = this[i] + 1; | |
return this.oneOfAKind(); | |
} | |
} | |
return this; | |
} | |
// Use this way | |
var result = [1,1,2,2,4,4,4,4,5].oneOfAKind(); | |
console.log(result.join()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment