DOkwufulueze/Ruby

Exercise 9: Implement Array Hash

Closed this issue · 3 comments

https://github.com/OkwufuluezeD/Ruby/tree/master/Exercise9

Array - HashCreate a method for Array that can create a hash having 'key' as length of the element and value as an array of all the elements of that length. Make use of for-in loop for the purpose.Eg: ['abc','def',1234,234,'abcd','x','mnop',5,'zZzZ'] should give result as {3=>["abc", "def", 234], 4=>[1234, "abcd", "mnop", "zZzZ"], 1=>["x", 5]}

https://github.com/OkwufuluezeD/Ruby/blob/master/Exercise9/lib/array.rb#L7

Does this work with the sample array given in the exercise? Please discuss if not clear.

Maybe I don't understand you as the array given in the exercise produces the expected output as shown below:

Enter items to make an array of
abc,def,1234,234,abcd,x,mnop,5,zZzZ
{3=>["abc", "def", 234], 4=>[1234, "abcd", "mnop", "zZzZ"], 1=>["x", 5]}

But in case you mean it should take array object as input, I've enabled that. So an input of
abc,def,1234,234,abcd,x,mnop,5,zZzZ & ['abc','def',1234,234,'abcd','x','mnop',5,'zZzZ'] will produce the same result.

Looks good.