Skip to main content
Commonmark migration
Source Link

##Swift 2, 116 bytes

Swift 2, 116 bytes

Regex is so verbose in Swift that doing this is much shorter

func e(s:String)->Int{var c=0;for k in s.utf8{if(c==0 ?k<65||k>90:k<97||k>122){return 0};c++};return s.utf8.count-1} 

This will return 0 or -1 (in the case of no input) for non-official names, and a number > 0 (which is equal to the length of the string - 1) if the name is official

###Ungolfed

Ungolfed

func e(s: String) -> Int{ var c = 0 for k in s.utf8{ if(c == 0 ? k < 65 || k > 90 : k < 97 || k > 122){ return 0 } c++ } return s.utf8.count - 1 } 

##Swift 2, 116 bytes

Regex is so verbose in Swift that doing this is much shorter

func e(s:String)->Int{var c=0;for k in s.utf8{if(c==0 ?k<65||k>90:k<97||k>122){return 0};c++};return s.utf8.count-1} 

This will return 0 or -1 (in the case of no input) for non-official names, and a number > 0 (which is equal to the length of the string - 1) if the name is official

###Ungolfed

func e(s: String) -> Int{ var c = 0 for k in s.utf8{ if(c == 0 ? k < 65 || k > 90 : k < 97 || k > 122){ return 0 } c++ } return s.utf8.count - 1 } 

Swift 2, 116 bytes

Regex is so verbose in Swift that doing this is much shorter

func e(s:String)->Int{var c=0;for k in s.utf8{if(c==0 ?k<65||k>90:k<97||k>122){return 0};c++};return s.utf8.count-1} 

This will return 0 or -1 (in the case of no input) for non-official names, and a number > 0 (which is equal to the length of the string - 1) if the name is official

Ungolfed

func e(s: String) -> Int{ var c = 0 for k in s.utf8{ if(c == 0 ? k < 65 || k > 90 : k < 97 || k > 122){ return 0 } c++ } return s.utf8.count - 1 } 
added 34 characters in body
Source Link
Jojodmo
  • 1.7k
  • 2
  • 14
  • 24

##Swift 2, 116 bytes

Regex is so verbose in Swift that doing this is much shorter

func e(s:String)->Int{var c=0;for k in s.utf8{if(c==0 ?k<65||k>90:k<97||k>122){return 0};c++};return s.utf8.count-1} 

This will return 0 or -1 (in the case of no input) for non-official names, and a number > 0 (which is equal to the length of the string - 1) if the name is official

###Ungolfed

func e(s: String) -> Int{ var c = 0 for k in s.utf8{ if(c == 0 ? k < 65 || k > 90 : k < 97 || k > 122){ return 0 } c++ } return s.utf8.count - 1 } 

##Swift 2, 116 bytes

Regex is so verbose in Swift that doing this is much shorter

func e(s:String)->Int{var c=0;for k in s.utf8{if(c==0 ?k<65||k>90:k<97||k>122){return 0};c++};return s.utf8.count-1} 

This will return 0 for non-official names, and a number > 0 (which is equal to the length of the string - 1) if the name is official

###Ungolfed

func e(s: String) -> Int{ var c = 0 for k in s.utf8{ if(c == 0 ? k < 65 || k > 90 : k < 97 || k > 122){ return 0 } c++ } return s.utf8.count - 1 } 

##Swift 2, 116 bytes

Regex is so verbose in Swift that doing this is much shorter

func e(s:String)->Int{var c=0;for k in s.utf8{if(c==0 ?k<65||k>90:k<97||k>122){return 0};c++};return s.utf8.count-1} 

This will return 0 or -1 (in the case of no input) for non-official names, and a number > 0 (which is equal to the length of the string - 1) if the name is official

###Ungolfed

func e(s: String) -> Int{ var c = 0 for k in s.utf8{ if(c == 0 ? k < 65 || k > 90 : k < 97 || k > 122){ return 0 } c++ } return s.utf8.count - 1 } 
Source Link
Jojodmo
  • 1.7k
  • 2
  • 14
  • 24

##Swift 2, 116 bytes

Regex is so verbose in Swift that doing this is much shorter

func e(s:String)->Int{var c=0;for k in s.utf8{if(c==0 ?k<65||k>90:k<97||k>122){return 0};c++};return s.utf8.count-1} 

This will return 0 for non-official names, and a number > 0 (which is equal to the length of the string - 1) if the name is official

###Ungolfed

func e(s: String) -> Int{ var c = 0 for k in s.utf8{ if(c == 0 ? k < 65 || k > 90 : k < 97 || k > 122){ return 0 } c++ } return s.utf8.count - 1 }