我目前正在学习 CoffeeScript,因为它比 JavaScript 更具“表现力”,因此,我想知道如何优化下面的代码
lastDay = 6
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
weeksToDivide = 0
for x in [1..9001]
if x % 5 == 0
if x % 4 == 0
if x % 3 == 0
nextDay = x
break
totalDays = lastDay + nextDay
day = (totalDays -= 7 while totalDays > 7)
weekday = weekdays[day[day.length - 1] - 1]
alert "Days until next meeting: #{nextDay}"
alert "That day is on a #{weekday}"
我主要是在寻找一种优化 if 嵌套的方法,但任何其他提示也将不胜感激。
提前致谢。
编辑:
我很愚蠢,忘记了数学是如何工作的,谢谢 Zeta。另外,感谢 Epidemia 的进一步优化。