数字ともアルファベットが2文字以上あるか調べる奴

Format
C
Post date
2019-10-19 13:38
Publication Period
Unlimited
  1. import Foundation
  2. enum CType { case alpha, num }
  3. let password = "1slkjld3fwiej"
  4. var set = Set<CType>()
  5. let r = password
  6. .reduce((alphaNG: true, numNG: true)) { r, c in
  7. (
  8. ("a"..."z").contains(c) || ("A"..."Z").contains(c) ? set.insert(.alpha).inserted : r.alphaNG,
  9. ("0"..."9").contains(c) ? set.insert(.num).inserted : r.numNG
  10. )
  11. }
  12. print(r)
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text