Created
January 15, 2018 04:51
-
-
Save prihandi/1ce1b4c60b2d96db9c3caabcf9f109b7 to your computer and use it in GitHub Desktop.
Revisions
-
prihandi created this gist
Jan 15, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ def create_isbn13(isbn_12) isbn_arr = isbn_12.to_s.chars.map(&:to_i) sumarr = isbn_arr.each.with_index.inject(0) { |sum,(value,index)| index.even? ? sum+(value*1) : sum+(value*3) } last_digit = (10 - (sumarr % 10)) % 10 isbn13 = isbn_12.to_s + last_digit.to_s end