Guest User

Untitled

a guest
Dec 11th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.20 KB | None | 0 0
  1. def checksum(isbn13)
  2. mod = isbn13.to_s.split(//).collect.with_index{|y,i| i.odd? ? y.to_i * 3 : y.to_i}.inject(:+) % 10
  3. mod == 0 ? 0 : 10 - mod
  4. end
  5.  
  6. puts checksum(978014300723)
  7. puts checksum("71")
Add Comment
Please, Sign In to add comment