- Коректно
- 4 успешни тест(а)
- 0 неуспешни тест(а)
def remove_duplicates(array)
array.to_set.to_a
end
.... Finished in 0.00875 seconds 4 examples, 0 failures
Срокът за предаване на решения е отминал
Обичате Ruby повече отколкото обичате спагети?
Готови сте с трета задача и ви сърбят пръстите за едно 5-минутно предизвикателство?
Няма проблеми - за тренировка и преговор на Enumerable, пускаме микроскопично предизвикателство.
Искаме да имплементирате функцията remove_duplicates
, която получава масив от
цели числа и връща масив, в който няма повтарящи се елементи.
remove_duplicates [-1, 4, -1, 33, 33, 42, 4] # [-1, 4, 33, 42]
Array#uniq
Array#uniq!
Примерните тестове се намират в GitHub хранилището с домашните. За информация как да ги изпълните, погледнете README-то на хранилището.
.... Finished in 0.00875 seconds 4 examples, 0 failures
.... Finished in 0.00879 seconds 4 examples, 0 failures
.... Finished in 0.00877 seconds 4 examples, 0 failures
.... Finished in 0.00868 seconds 4 examples, 0 failures
.... Finished in 0.00871 seconds 4 examples, 0 failures
.... Finished in 0.00873 seconds 4 examples, 0 failures
.... Finished in 0.00858 seconds 4 examples, 0 failures
.... Finished in 0.00864 seconds 4 examples, 0 failures
.... Finished in 0.00879 seconds 4 examples, 0 failures
.... Finished in 0.00874 seconds 4 examples, 0 failures
.... Finished in 0.0082 seconds 4 examples, 0 failures
.... Finished in 0.0086 seconds 4 examples, 0 failures
.... Finished in 0.00852 seconds 4 examples, 0 failures
.... Finished in 0.00877 seconds 4 examples, 0 failures
.... Finished in 0.0087 seconds 4 examples, 0 failures
.... Finished in 0.00866 seconds 4 examples, 0 failures
.... Finished in 0.01061 seconds 4 examples, 0 failures
.... Finished in 0.00871 seconds 4 examples, 0 failures
.... Finished in 0.01044 seconds 4 examples, 0 failures
.... Finished in 0.00845 seconds 4 examples, 0 failures
.... Finished in 0.00862 seconds 4 examples, 0 failures
.... Finished in 0.00865 seconds 4 examples, 0 failures
.... Finished in 0.00865 seconds 4 examples, 0 failures
.... Finished in 0.00866 seconds 4 examples, 0 failures
.... Finished in 0.01008 seconds 4 examples, 0 failures
.... Finished in 0.00861 seconds 4 examples, 0 failures
.... Finished in 0.00871 seconds 4 examples, 0 failures
.... Finished in 0.0087 seconds 4 examples, 0 failures
.... Finished in 0.00832 seconds 4 examples, 0 failures
.... Finished in 0.00878 seconds 4 examples, 0 failures
.... Finished in 0.00861 seconds 4 examples, 0 failures
.... Finished in 0.00863 seconds 4 examples, 0 failures
.... Finished in 0.00869 seconds 4 examples, 0 failures
.... Finished in 0.00895 seconds 4 examples, 0 failures
.... Finished in 0.00871 seconds 4 examples, 0 failures
.... Finished in 0.00959 seconds 4 examples, 0 failures
.... Finished in 0.0087 seconds 4 examples, 0 failures
.... Finished in 0.0088 seconds 4 examples, 0 failures
...F Failures: 1) remove_duplicates removes duplicates and preserves the order Failure/Error: expect(remove_duplicates [42, 2, -2, 4, 5, 5, 7, 33, 42, 5, 14, -2]). expected: [42, 2, -2, 4, 5, 7, 33, 14] got: [-2, 2, 4, 5, 7, 14, 33, 42] (compared using ==) # /tmp/d20141106-18133-5df0r2/spec.rb:20:in `block (2 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00927 seconds 4 examples, 1 failure Failed examples: rspec /tmp/d20141106-18133-5df0r2/spec.rb:19 # remove_duplicates removes duplicates and preserves the order
.... Finished in 0.00865 seconds 4 examples, 0 failures
.... Finished in 0.00861 seconds 4 examples, 0 failures
.... Finished in 0.00867 seconds 4 examples, 0 failures
.... Finished in 0.00866 seconds 4 examples, 0 failures
.... Finished in 0.00868 seconds 4 examples, 0 failures
.... Finished in 0.00862 seconds 4 examples, 0 failures
.... Finished in 0.00834 seconds 4 examples, 0 failures
.... Finished in 0.00823 seconds 4 examples, 0 failures
.... Finished in 0.00874 seconds 4 examples, 0 failures
.... Finished in 0.00873 seconds 4 examples, 0 failures
.... Finished in 0.0084 seconds 4 examples, 0 failures
.... Finished in 0.00862 seconds 4 examples, 0 failures
.... Finished in 0.00885 seconds 4 examples, 0 failures
.... Finished in 0.00884 seconds 4 examples, 0 failures
.... Finished in 0.00883 seconds 4 examples, 0 failures
.... Finished in 0.00862 seconds 4 examples, 0 failures
.... Finished in 0.00854 seconds 4 examples, 0 failures
.... Finished in 0.00877 seconds 4 examples, 0 failures
.... Finished in 0.00862 seconds 4 examples, 0 failures
.... Finished in 0.00871 seconds 4 examples, 0 failures
.... Finished in 0.00862 seconds 4 examples, 0 failures
.... Finished in 0.00887 seconds 4 examples, 0 failures
.... Finished in 0.00863 seconds 4 examples, 0 failures
.... Finished in 0.00877 seconds 4 examples, 0 failures
.... Finished in 0.00861 seconds 4 examples, 0 failures
.... Finished in 0.00875 seconds 4 examples, 0 failures
.... Finished in 0.00874 seconds 4 examples, 0 failures
.... Finished in 0.00876 seconds 4 examples, 0 failures
.... Finished in 0.00869 seconds 4 examples, 0 failures
.... Finished in 0.00865 seconds 4 examples, 0 failures
.... Finished in 0.00873 seconds 4 examples, 0 failures
.... Finished in 0.00855 seconds 4 examples, 0 failures
.... Finished in 0.0087 seconds 4 examples, 0 failures
.... Finished in 0.0086 seconds 4 examples, 0 failures
.... Finished in 0.00873 seconds 4 examples, 0 failures