Created
October 18, 2023 12:06
-
-
Save johnpaulmanoza/05552328b8039687e658b7fdabfcc403 to your computer and use it in GitHub Desktop.
Revisions
-
johnpaulmanoza created this gist
Oct 18, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ func solution(startAtDay: String, num: Int) -> String? { let days: [String] = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] guard days.contains(startAtDay) else { return nil } let index = (days.firstIndex(of: startAtDay) ?? 0) + 1 let value = index + num let normalizedNo = (value - 1) % 7 + 1 switch normalizedNo { case 1: return days[0] case 2: return days[1] case 3: return days[2] case 4: return days[3] case 5: return days[4] case 6: return days[5] case 7: return days[6] default: return nil } } if let answer = solution(startAtDay: "Sun", num: 23) { print("Day -> ", answer) }