Last active
August 21, 2020 08:39
-
-
Save yungyungGwon/03a4584711fef8e00297c6f5af99ae28 to your computer and use it in GitHub Desktop.
Algorithm
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(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