Created
September 9, 2019 20:06
-
-
Save xicond/949d2cc34380ca7167e1f70112f0e8ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//repl.it/repls/LimeWholeRedundancy | |
function solution(record) { | |
var answer = []; | |
var dbUser = {}; | |
for (var index in record) { | |
var commands = record[index].split(' '); | |
switch(commands[0]) { | |
case 'Enter': | |
answer.push(commands[1] + ' came in.'); | |
if (commands[2]) { | |
dbUser[commands[1]] = commands[2]; | |
} | |
break; | |
case 'Leave': | |
answer.push(commands[1] + ' has left.'); | |
break; | |
case 'Change': | |
if (commands[2]) { | |
dbUser[commands[1]] = commands[2]; | |
} | |
} | |
} | |
for (index in answer) { | |
for (var userId in dbUser) { | |
answer[index] = answer[index].replace(userId, dbUser[userId]); | |
} | |
} | |
return answer; | |
} | |
console.log(solution(["Enter uid1234 Muzi", "Enter uid4567 Prodo", "Leave uid1234", "Enter uid1234 Prodo", "Change uid4567 Ryan"])) |
This file contains hidden or 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
//repl.it/repls/RapidBigVisitors | |
function solution(N, users) { | |
var answer = []; | |
var keyValue = []; | |
for(var i=1; i<=N; i++) { | |
var numberOfFail = 0; | |
var numberOfReached = 0; | |
for(var index in users) { | |
var stage = users[index]; | |
if (stage==i) { | |
numberOfFail++; | |
} | |
if (stage>=i) { | |
numberOfReached++; | |
} | |
} | |
keyValue.push({key: i, val:numberOfFail/numberOfReached}); | |
} | |
keyValue = keyValue.sort(function (a, b) { | |
return a.val < b.val; | |
}); | |
for(index in keyValue) { | |
answer.push(keyValue[index].key); | |
} | |
return answer; | |
} | |
console.log(solution(5, [2,1,2,6,2,4,3,3])); |
This file contains hidden or 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
//repl.it/repls/PhysicalMatureAdaware | |
function solution(relation) { | |
var answer = 0; | |
var combinations = []; | |
// first combinations | |
for (var row in relation) { | |
var columns = relation[row]; | |
for (var i=0; i<columns.length; i++) { | |
if (combinations[i]==undefined) { | |
combinations[i] = {}; | |
combinations[i][columns[i]] = {}; | |
combinations[i][columns[i]] = 1; | |
} | |
else if (combinations[i][columns[i]]== undefined) { | |
combinations[i][columns[i]] = 1; | |
} | |
else if (combinations[i][columns[i]]) { | |
combinations[i] = false; | |
} | |
} | |
} | |
var tookColumns = []; | |
for (row in combinations) { | |
if (combinations[row]) { | |
tookColumns[row] = 1; | |
answer ++; | |
} else { | |
delete combinations[row]; | |
} | |
} | |
// second combinations | |
combinations = {}; | |
for (var row in relation) { | |
var columns = relation[row]; | |
for (var i=0; i<columns.length-1; i++) { | |
if (tookColumns[i]) { | |
continue; | |
} | |
for (var j=i+1; j<columns.length; j++) { | |
if (tookColumns[j]) { | |
continue; | |
} | |
if (combinations[i+'x'+j]==undefined) { | |
combinations[i+'x'+j] = {}; | |
combinations[i+'x'+j][columns[i]] = {}; | |
combinations[i+'x'+j][columns[i]][columns[j]] = 1; | |
} else if (combinations[i+'x'+j][columns[i]]==undefined) { | |
combinations[i+'x'+j][columns[i]] = {}; | |
combinations[i+'x'+j][columns[i]][columns[j]] = 1; | |
} | |
else if (combinations[i+'x'+j][columns[i]][columns[j]]==undefined) { | |
combinations[i+'x'+j][columns[i]][columns[j]] = 1; | |
} | |
else if (combinations[i+'x'+j][columns[i]] && combinations[i+'x'+j][columns[i]][columns[j]]) { | |
combinations[i+'x'+j] = false; | |
} | |
} | |
} | |
} | |
for (row in combinations) { | |
if (combinations[row]) { | |
answer ++; | |
} | |
} | |
return answer; | |
} | |
console.log(solution([["100","ryan","music","2"],["200","apeach","math","2"],["300","tube","computer","3"],["400","con","computer","4"],["500","muzi","music","3"],["600","apeach","music","2"]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment