0

Spy Life Code Coach (Swift) - Shortcut?

I just solved the code coach "the spy life" with Swift, but I am wondering if there's an easier way to code it. I don't think we can post direct solutions here, but basically I learned to use .reversed() to reverse it and then I used a switch case to list EVERY lowercase and uppercase letter of the alphabet plus a space as the characters that should print (see below). Is there a shorter way to have done this? Is there a way to tell it to only choose alphabetically characters so I don't have to list all 52 of them??? for letter in reversed.characters { switch letter { case "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", " ": print(letter) default: break } }

15th Nov 2020, 2:35 AM
Michelle
Michelle - avatar
2 ответов
0
Interesting! I didnt know greater than or equal than signs could be used with letters. That's very good to know. Thanks for the help!
15th Nov 2020, 10:31 PM
Michelle
Michelle - avatar