Created
September 12, 2017 20:49
-
-
Save ceci21/c4be3f76154c501c3afa2ebd94f19836 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
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