Skip to content

Instantly share code, notes, and snippets.

@urubatan
Created October 21, 2022 13:56
Show Gist options
  • Save urubatan/e845825f3aee9c8cd3e824e18eb446a2 to your computer and use it in GitHub Desktop.
Save urubatan/e845825f3aee9c8cd3e824e18eb446a2 to your computer and use it in GitHub Desktop.
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