[英]How do I use a look up table to reflect certain outputs?
我想根據他們有多少代理來呈現某些字符串......例如。
第 1 層:1-4 個代理
第 2 層:5-9 名特工
第 3 層:10 多個代理
如果用戶有 4 個代理......它應該呈現“ TIER 1 1 more agent to access Tier 2”
如果用戶有 6 個代理......它應該呈現“ TIER 2 4 more agent to access Tier 3”
如果一個用戶有超過 10 個代理......它應該呈現“第 3層您已達到最高層!”
currentTier(agentsCount) {
if (agentsCount <= 4) {
return 1;
} else if (agentsCount >= 5 || agentsCount <= 9) {
return 2;
} else if (agentsCount >= 10) {
return 3;
}
}
nextTier(agentsCount) {
let currentTier = this.currentTier(agentsCount);
if (currentTier === 1) {
return 2;
} else if (currentTier === 2) {
return 3;
} else if (currentTier === 3) {
return false;
}
}
toNextTierMessage(agentsCount) {
let nextTier = this.nextTier(agentsCount),
toNextTier = 0;
let currentTier = this.currentTier(agentsCount);
if (currentTier === 1) {
toNextTier = 5 - agentsCount;
} else if (currentTier === 2) {
toNextTier = 10 - agentsCount;
}
if (currentTier <= 2) {
return toNextTier+ ' more agents to access Tier '+nextTier;
} else if (currentTier >= 3) {
return 'You\'ve reached the highest tier!';
}
}
這個怎么樣:
function nextLevelMessage(agents) {
return agents< 5?"TIER 1. "+( 5-agents)+" more agent(s) to access Tier 2.":
agents<10?"TIER 2. "+(10-agents)+" more agent(s) to access Tier 3.":
"TIER 3. You've reached the highest tier!";
}
檢查代理是否為0
或未通過任何內容...
如果小於 5,我們已經返回 1,因此無需再次測試;如果小於 10,我們已經返回 2,因此我們可以捕獲 3。
const currentTier = agentsCount => agentsCount <= 4 ? 1 : agentsCount <= 9 ? 2 : 3;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.