-
-
Save anonymous/e3b3d9aac9b21c2b7ed1 to your computer and use it in GitHub Desktop.
This file contains 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 characters
number = 1234567890 | |
num_string = number.to_s | |
num_array = [] | |
work_array = [] | |
num_string.each_char {|c| num_array.push(c)} | |
for i in 0..4 | |
work_array.push(num_array.shift.to_i) | |
end | |
work_array.each {|i| puts "#{i} is #{work_array[i].class}"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
no reason to convert integer to string, just wrap it in quotes
num_string = "1234567890"
using the .split method will convert a string of characters into an array
num_array = num_string.split("")
use map to convert the array of strings into integers and store in a new variable
work_array = num_array.map { |num| num.to_i}
work_array.each { |i| puts "#{i} is #{i.class}"}