Created
October 21, 2022 13:56
-
-
Save urubatan/e845825f3aee9c8cd3e824e18eb446a2 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 scoreboard(initial) { | |
if(Object.keys(initial).length < 2){ | |
throw new Exception('you need at least two players') | |
} | |
stored = {} | |
for (x in initial){ | |
var v = parseInt(initial[x]) | |
if(v.isNa)N | |
stored[x.toLowerCase()] = | |
} | |
function result(){ | |
for(x in stored) { | |
console.log(x[0].toUpperCase() + x.substring(1) + ':' + stored[x].toString()) | |
} | |
} | |
result.point = function(name,value){ | |
if(!value){ | |
value=1 | |
} | |
name = name.toLowerCase() | |
if(stored[name]){ | |
stored[name] += value | |
} | |
} | |
result.add = function(name,value){ | |
if(!value){ | |
value=1 | |
} | |
name = name.toLowerCase() | |
if(!stored[name]){ | |
stored[name] = value | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment