我有一個TypeScript方法。它將整數值轉換/映射到字符串天。我該如何將此代碼改進爲更高效的代碼?任何想法?optmise if else條件javaScript
private _convertIntToStringDays(days: any){
let dayArray: any = [];
for (let day in days){
if (days[day] == 1){
dayArray.push('monday');
}
else if (days[day] == 2){
dayArray.push('tuesday');
}
else if (days[day] == 3){
dayArray.push('wednesday');
}
else if (days[day] == 4){
dayArray.push('thursday');
}
else if (days[day] == 5){
dayArray.push('friday');
}
else if (days[day] == 6){
dayArray.push('saturday');
}
else if (days[day] == 0){
dayArray.push('sunday');
}
}
dayArray.shift(dayArray[0]);
console.log(dayArray);
return dayArray;
}
看起來更像是打字稿或流動到我... – haim770
對不起它打字稿 – blackdaemon
日子我得到是整數值 – blackdaemon