Created
July 19, 2021 04:16
-
-
Save NickChen14/3cc9aea71188ceea020e150a90d312f2 to your computer and use it in GitHub Desktop.
Dayofweek - en96321
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 修改前 | |
function solution(S, K) { | |
const d = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] | |
const nowDat = d.findIndex(item => item === S) | |
const add = K % 7 | |
if (add <= 6 - nowDat) { | |
return d[nowDat + add] | |
} | |
return d[add - (6 - nowDat + 1)] | |
// write your code in JavaScript (Node.js 8.9.4) | |
} | |
// 修改後 | |
function solution (S, K) { | |
const dat = ['Mon', 'Tue', 'Wed', 'Sur', 'Fri', 'Sat', 'Sun'] | |
const nowDat = dat.findIndex(d => d === S) | |
return dat[(nowDat + K) % 7] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment