Skip to content

Instantly share code, notes, and snippets.

@petrokoriakin
Last active October 31, 2018 10:14
Show Gist options
  • Save petrokoriakin/aac2efdc86010a755ac83cb2b3e38a0a to your computer and use it in GitHub Desktop.
Save petrokoriakin/aac2efdc86010a755ac83cb2b3e38a0a to your computer and use it in GitHub Desktop.
ruby-trainee-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/petrokoriakin/trainee-task-4

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

Треба заімплементити методи

  • .comments_quantity
  • #сomments
  • #add_comment

Їх поведінка описана в спеках https://github.com/petrokoriakin/trainee-task-4/blob/master/library_manager_spec.rb#L7

5. Поправить ексепшн в джаваскрипте. Что надо добавить, чтоб ексепшина не было и код работал? Если не знаете - не беда, просто расскажите словами что делает этот код?

Есть код, при выполнении которого вываливается ексепшн

  function getCurrentState(event) {
    var map = event.target
    var current_zoom = map.getZoom();
    var the_function = getCurrentState;

    $('#map-zoom').html(current_zoom);
    visible_areas = []
    visible_markers = []

    map.eachLayer(function (layer) {
      if ((layer instanceof L.Marker) && ( map.getBounds().contains(layer.getLatLng()) )) {
        if ( !layer.options.isLocation && layer.options.zipCode ){
          if (typeof(layer.options.zipCode) != 'undefined') {
            visible_areas.push(layer.options.zipCode)
          }
        } else {
          if (typeof(layer.options.zipCodeAbbrev) != 'undefined') {
            visible_markers.push(layer.options.zipCodeAbbrev)
          } else {
            if ( typeof(layer._markers) != 'undefined' && layer._markers instanceof Array ) {
              $.each(layer._markers, function( index, marker ) {
                if (typeof(marker.options.zipCodeAbbrev) != 'undefined') {
                  visible_markers.push(marker.options.zipCodeAbbrev)
                }
              });
            }
          }
        }
      }
    });
    $('#visible-locations').html(visible_areas.join(' '));
    if (visible_areas.length != 0) {
      currentURL = prepareUrlParams(visible_areas)
    } else {
      currentURL = prepareUrlParams(visible_markers)
    }
    $.get(currentURL, function() {
      mаp.eachLayer(function (layer) {
        if ((layer instanceof L.Marker) || (layer instanceof L.MarkerClusterGroup) || (layer instanceof L.FeatureGroup)) {
          layer.clearAllEventListeners();
          map.removeLayer(layer);
        }
      });
      var bounds = map.getBounds();
      var markers = L.markerClusterGroup();
      $.each(marker_locations, function( index, marker ) {
        markers.addLayer(
          L.marker(
            [marker[0], marker[1]],
            {
              isLocation: true,
              zipCodeAbbrev: marker[3]
            }
          ).bindPopup(marker[2])
        );
      });
      map.addLayer(markers);

      var fancy_marker = L.icon({iconUrl: 'zip_marker.png'});
      $.each(invisible_marker_locations, function( index, marker ) {
         map.addLayer(
          L.marker(
            [marker[0], marker[1]], 
            { icon: fancy_marker,
              zipCode: marker[2],
              isLocation: false
            }
          )
        );
      });

      if (render_center_user_location) {
        var star_marker = L.icon({iconUrl: 'star.png'});
        var star =  L.marker(
          [user_location.lat, user_location.lng], 
          { icon: star_marker }
        )
        map.addLayer(star);
      }

      map.on('zoomend', the_function);
      map.on('moveend', the_function);
      $('#visible-markers').html(marker_locations.length);
    })

    map.off('zoomend', getCurrentState);
    map.off('moveend', getCurrentState);
  }

Вот, собственно, ексепшн

(index):555 Uncaught ReferenceError: mаp is not defined
    at Object.success ((index):555)
    at fire (jquery.self-bd7ddd3….js?body=1:3233)
    at Object.fireWith [as resolveWith] (jquery.self-bd7ddd3….js?body=1:3363)
    at done (jquery.self-bd7ddd3….js?body=1:9841)
    at XMLHttpRequest.callback (jquery.self-bd7ddd3….js?body=1:10312)
(anonymous)	@	(index):555
fire	@	jquery.self-bd7ddd3….js?body=1:3233
fireWith	@	jquery.self-bd7ddd3….js?body=1:3363
done	@	jquery.self-bd7ddd3….js?body=1:9841
callback	@	jquery.self-bd7ddd3….js?body=1:10312

6. Завдання:

використовуючи лише Rack(http://rack.github.io) написати простий веб додаток, який розбирає набір вхідних параметрів в GET запиті(приклад: http://localhost:9292/?field1=value1&field2=value2&field3=value3) та повертає їх в веб браузер у вигляді таблиці:

key value
field1 value1
field2 value2
field3 value3

(пояснення, як працювати з Rack можна знайти тут: https://gist.github.com/markbates/4240848)

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