Skip to content

Instantly share code, notes, and snippets.

@shved270189
Forked from petrokoriakin/ruby-trainee-position.md
Last active November 16, 2017 12:53
Show Gist options
  • Save shved270189/961cb565d86c62b242eaf54cef4c3589 to your computer and use it in GitHub Desktop.
Save shved270189/961cb565d86c62b242eaf54cef4c3589 to your computer and use it in GitHub Desktop.
ruby-position

###Тестовое задание

#####1. Добавить к классу Array метод, который будет возвращать индекс элемента, при условии что массив может быть вложенным

a = [
  'hash',
  'array',
  [
    'map',
    [
      'rails',
      'assets',
      'actioncable',
      'REST'
    ],
    'inject',
    'reduce',
    'detect'
  ],
  'metaptogramming',
  'recursion',
  [
    'css3',
    'ecmascript6',
    'sublimetext',
    'heroku'
  ],
  'activerecord',
  'ember'
]

a.deep_index("REST") #=> [2,1,3]
a.deep_index("ember") #=> [7]

#####2. Реализовать метод AnaliticsService#analyze_data

class AnalyticsService

  def analyze_data
    # your code goes here
  end
end

data = [['United States', 34.8], ['Ukraine', 165.2], ['United States', 40.0],['Panama', 220.45],['China', 2134.56],['Ukraine', 34.8]]

AnalyticsService.new.analyze_data(data) #=> { 'Ukraine' => 200.0, 'Panama' => 220.45, 'China' => 2134.56, 'United States', 74.8 }

#####3. Отсортировать массив строк в определенном порядке.

class AwesomeSorter
  def self.sort!
    # your code goes here
  end
end

companies = [
  'Adobe',
  'microsoft inc.',
  'bCreative',
  '1000Museums',
  'Adidas',
  'ABIBAS',
  'ReeBook',
  'royalty-holding llc',
  'Rexona',
  'aliexpress',
  'booking.com'
]

AwesomeSorter.sort!(companies)

puts companies #=>
# 1000Museums
# ABIBAS
# Adidas
# Adobe
# aliexpress
# bCreative
# booking.com
# microsoft inc.
# ReeBook
# Rexona
# royalty-holding llc

#####4. Реализовать модуль Commentable

Заготовка для задания тут: https://github.com/shved270189/test-task-4

Сам модуль тут: https://github.com/shved270189/test-task-4/blob/master/library/commentable.rb#L4

Необходимо заимплементировать методы

  • .comments_quantity
  • #сomments
  • #add_comment

Их поведение описано в тестах Rspec https://github.com/shved270189/test-task-4/blob/master/library_manager_spec.rb#L7

#####5. Отрефакторить SkuValidator под rubocop https://github.com/bbatsov/rubocop . Сейчас там 165 ошибок.

https://github.com/shved270189/product_service

https://github.com/shved270189/product_service/blob/master/lib/sku_validator.rb#L1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment