Skip to content

Instantly share code, notes, and snippets.

@yungyungGwon
Last active August 21, 2020 08:39
Show Gist options
  • Save yungyungGwon/03a4584711fef8e00297c6f5af99ae28 to your computer and use it in GitHub Desktop.
Save yungyungGwon/03a4584711fef8e00297c6f5af99ae28 to your computer and use it in GitHub Desktop.
Algorithm
function solution(string, n){
var answer = [];
var empt = []
for(var i = 0; i < string.length; i++){
empt[i] = string[i].charAt(n);
}
empt.sort();
console.log(empt);
for(var i = 0 ; i < string.length; i++){
for(var j = 0; j < empt.length; j++){
if(string[i].charAt(n) == empt[j] && string[j] != answer[j]){
answer[i] = string[j];
if(string[i] != string[j] && string[i].charAt(n) == string[j].charAt(n)){
answer.sort();
break;
}
}
}
}
return answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment