Sum an Array of String Based Integers in Ruby

0
2319

This guide examines an efficient process for summing an array filled with string based integers in Ruby.

Summary

Implement a method that takes in an array of string based integers that returns the sum of all of the integer values.

Exercise File

Code File

Exercise Description

Given the following array of strings:

["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"]

Build out a method that converts the string values to integers and then totals the integers.

Expected Output

string_sum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"])
# 210

Real World Usage

This exercise will test two important development components:

  • Converting a data collection to a different data type.
  • Performing calculations on a collection of values.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here