Skip to content

Instantly share code, notes, and snippets.

@rikuTanide
Last active Aug 27, 2021
Embed
What would you like to do?
途中でReturnしないIF文
Buyability isBuyable(request) {
var result = new Buyability();
// ログインしているか
if (isLoggedIn(request)) {
// 在庫があるか
if (hasStock(request)) {
// お金は足りているか
if (hasMoney(request)) {
result.buyable = true;
} else {
result.buyalbe = false;
result.reason = "money";
}
} else {
// 再入荷可能か
if (canRestocked(request)) {
// お金は足りているか
if (hasMoney(request)) {
result.buyable = true;
} else {
result.buyable = false;
result.reason = "money";
}
} else {
result.buyable = false;
result.reason = "stock";
}
}
} else {
result.buyable = false;
result.reason = "login";
}
return result;
}
class Buyability {
bool buyable;
String reason;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment