Created
March 31, 2017 14:50
-
-
Save Obre/1610a1144618241264e541abbe99101c 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
function solution(myArr) { | |
var myArr = [9, 3, 9, 3, 9, 7, 9, 4, 5, 6, 8, 3, 4, 1, 2, 5, 6, 7, 7, 4, 2]; | |
var sortedArray = myArr.slice().sort(); | |
var pairedArray = []; | |
var leftUnpaired = []; | |
console.log(sortedArray); | |
var i; | |
for (i = 0; i < sortedArray.length - 1; i++) { | |
if (sortedArray[i + 1] == sortedArray[i] || sortedArray[i - 1] == sortedArray[i]) { | |
pairedArray.push(sortedArray[i]); | |
} else if (sortedArray[i + 1] != sortedArray[i]) { | |
leftUnpaired.push(sortedArray[i]) | |
} | |
} | |
console.log(pairedArray); | |
console.log(leftUnpaired); | |
} | |
solution(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment