the way I was trying to solve the 2.3 challenge has reached its' limits. Here's the code I've been using
class String
def every_other_char
arrays = self.split("").each_slice(2).to_a
arrays.each do |array|
array.pop
end
arrays.join
end
end
And here' the error message
1) String#every_other_char "Four score and seven years ago..." -> "Fu cr n ee er g.."
Failure/Error: expect(input.every_other_char).to eq output
expected: "Fu cr n ee er g.."
got: "Fu cr n ee er g."
Now I know why what's causing the error, just not how to fix it.
I'm splitting the array into sub arrays of 2, but the last sub array has only one element in it. So I end up with something like this [[......] , [[ . ] , [ . ] ] , [ . ]]
So when the program reaches the dots it pops out the last dot in the second to last sub-array, and reaches the end and pops out the last sub array. This means I'm returning one dot instead of two.
I know this is quite convoluted, but I hope it makes sense.
My issue is can this challenge be solved this way at all? I'm not sure how to circumvent the odd number of elements issue. Does anyone know how to solve this?
Hi guys,
the way I was trying to solve the 2.3 challenge has reached its' limits. Here's the code I've been using
And here' the error message
Now I know why what's causing the error, just not how to fix it.
I'm splitting the array into sub arrays of 2, but the last sub array has only one element in it. So I end up with something like this [[......] , [[ . ] , [ . ] ] , [ . ]]
So when the program reaches the dots it pops out the last dot in the second to last sub-array, and reaches the end and pops out the last sub array. This means I'm returning one dot instead of two.
I know this is quite convoluted, but I hope it makes sense.
My issue is can this challenge be solved this way at all? I'm not sure how to circumvent the odd number of elements issue. Does anyone know how to solve this?
Thanks!!