Guest User

Untitled

a guest
Sep 11th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.28 KB | None | 0 0
  1. enum ChessColor {
  2.     case black
  3.     case white
  4. }
  5.  
  6. func chessBoard(x: String, y: Int) -> ChessColor? {
  7.     guard x.count == 1,
  8.     let index = "abcdefgh".range(of: x)?.lowerBound.encodedOffset else {
  9.         return nil
  10.     }
  11.  
  12.     return (index + y) % 2 == 0 ? .white : .black
  13. }
Advertisement
Add Comment
Please, Sign In to add comment