Skip to content

Instantly share code, notes, and snippets.

@OfTheDelmer
Created September 24, 2013 19:22
Show Gist options
  • Save OfTheDelmer/6689911 to your computer and use it in GitHub Desktop.
Save OfTheDelmer/6689911 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