Skip to content

Instantly share code, notes, and snippets.

@IAMIronmanSam
Created April 3, 2019 04:36
Show Gist options
  • Save IAMIronmanSam/7eb9613a57f2292a76c109a84d6160bc to your computer and use it in GitHub Desktop.
Save IAMIronmanSam/7eb9613a57f2292a76c109a84d6160bc to your computer and use it in GitHub Desktop.
function countUniqueValues(arr){
if(arr.length === 0) return 0;
var i = 0;
for(var j = 1; j < arr.length; j++){
if(arr[i] !== arr[j]){
i++;
arr[i] = arr[j]
}
}
return i + 1;
}
countUniqueValues([1,2,2,5,7,7,99])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment