Last active
August 29, 2015 14:00
-
-
Save arton/11347127 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 swichFunc(x, cond) { | |
for (var i = 0; i < cond.length; i++) { | |
if (cond[i].cond(x)) { | |
return cond[i].proc(x); | |
} | |
} | |
} | |
function swichAction(x, cond, continuous) { | |
for (var i = 0; i < cond.length; i++) { | |
if (cond[i].cond(x)) { | |
cond[i].proc(x); | |
if (!continuous) break; | |
} | |
} | |
} | |
var judgeNaturalNumber = function(x) { | |
console.log(swichFunc(x, [ | |
{ cond: function(x) { return x < 0 }, | |
proc: function(x) { return x + " は自然数ではありません." }, | |
}, | |
{ cond: function(x) { return x === 0 }, | |
proc: function(x) { return "ここでは 0 は自然数です." }, | |
}, | |
{ cond: function(x) { return x > 0 }, | |
proc: function(x) { return x + " は正の数です." }, | |
}, | |
{ cond: function(x) { return true }, | |
proc: function(x) { return x + " は数ではないようです." }, | |
}, | |
])); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment