Skip to content

Instantly share code, notes, and snippets.

@arton arton/gist:11347127
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.