I would like to ask you for an opinion.

I had to do an assignment in Ruby and I did 3 solutions as exercise and I would like to know what you think about or suggestions regarding the requirements I had below.

My Solutions:

https://paste.ofcode...AG4N2awc25mPQFc

def simplify(arr) # Use implicit function to sort the array sorted_array = arr.sort # Define new array to be returned uniq_array = Array.new if sorted_array.length > 0 # If the array does not already contain the element, add it to the uniq_array sorted_array.map { |arr| uniq_array << arr unless uniq_array.include?(arr)} puts uniq_array end uniq_array end def simplify2(arr) arr = arr.inject([]) do |uniq_arr, value| uniq_arr << value unless uniq_arr.include? value uniq_arr arr.sort end end def simplify3(arr) ordered_array = arr.sort { |a,b| a <=> b } uniq_array = [] # look if next elem diff from current, skip if equals ordered_array.each_index do |i| current_element = ordered_array[i] next if current_element == ordered_array[i+1] uniq_array.push(current_element) end uniq_array end

Write a function called “simplify” that takes a single parameter: An array of integers.

Your function should return a new array that is sorted (in ascending order), with all duplicates removed:

So for instance, if I passed in:

[0, 9, 8, 3, 3, 3, 5, 9, 5, 0]

Your function would return:

[0, 3, 5, 8, 9]

1) We assume your language has function that can sort an array. If it doesn’t, just pretend it does. We don’t expect you to write a sort algorithm. If you’re lucky enough to use a language has a built-in way to remove duplicates, please don’t use that. We’d like to see you write that part out.

2) Clarity of your code is more important than raw typing speed. So, refactoring to improve your solution is just fine.

This post has been edited by **modi123_1**: 10 February 2018 - 01:36 PM

Reason for edit:: Added the actual code