Skip to content

Instantly share code, notes, and snippets.

@KillerDesigner
Forked from OfTheDelmer/arrayPrac.rb
Created October 6, 2013 01:45
Show Gist options
  • Save KillerDesigner/6848337 to your computer and use it in GitHub Desktop.
Save KillerDesigner/6848337 to your computer and use it in GitHub Desktop.
# We want a method that splits an array on an index and
# removes everything afterward
# Example: myArray = [1, 2, 3, 4, 5, 6]
# splice(3, myArray) => [1,2,3,4]
myArray = [1,2,3,4,5,6]
puts "Give my an index"
index = gets.chomp().to_i
# Try using a loop and creating a new Array, (maybe shovel)
x =0
newArray = []
while x < index
# do stuff here
newArray << myArray[x]
x += 1
end
p newArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment