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
import Foundation | |
func israeliIDValidator(idNum: String) -> Bool { | |
guard Int(idNum) != nil else { return false } | |
return ("00000000" + idNum).suffix(9).enumerated().reduce(0) { | |
let step = Int(String($1.1))! * ($1.0 % 2 + 1) | |
return $0 + (step > 9 ? step - 9 : step) | |
} % 10 == 0 | |
} |