Skip to content

Instantly share code, notes, and snippets.

@ceci21
Created September 12, 2017 20:49
Show Gist options
  • Save ceci21/c4be3f76154c501c3afa2ebd94f19836 to your computer and use it in GitHub Desktop.
Save ceci21/c4be3f76154c501c3afa2ebd94f19836 to your computer and use it in GitHub Desktop.
var unique = function(array) {
function sortArray(myArr) {
for (var i = 0; i < myArr.length; i++) {
for (var n = 0; n < myArr.length; n++) {
if (n === 0) {
continue;
} else {
if (myArr[n] < myArr[n - 1]) {
var temp = myArr[n];
myArr[n] = myArr[n - 1];
myArr[n - 1] = temp;
}
}
}
}
return myArr;
}
function removeDuplicates(myArr) {
for (var i = 0; i < myArr.length; i++) {
var num = myArr[i];
if (myArr[i + 1] === num) {
myArr.splice(i, 1);
i--;
}
}
return myArr;
}
var arr = [];
for (var i = 0; i < array.length; i++) {
arr.push(array[i]);
}
return removeDuplicates(sortArray(arr));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment