Sha256: e0ca6fe5a2082d53e24c93164f6954347de80d75ce19fd1842d5448fbd15f986
Contents?: true
Size: 635 Bytes
Versions: 11
Compression:
Stored size: 635 Bytes
Contents
module UOB module Payroll class StringCalculator attr_reader :string class << self def calculate(string) new(string).calculate end end def initialize(string) @string = string end # The sum of each byte converted into ASCII multiplied to it's index. # For example: # BLA #=> 413 # B ~> 66 * 1 # L ~> 76 * 2 # A ~> 65 * 3 def calculate string. each_byte. to_a. each_with_index. map { |byte, index| (index + 1) * byte }. reduce(0, :+) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems