K
K
krll-k2017-05-25 00:38:59
JavaScript
krll-k, 2017-05-25 00:38:59

Why can't I sort the collection using the sortBy method of underscore?

var collection = [ { city: 'томск', count: '1185' },
  { city: 'йошкар ола', count: '1276' },
  { city: 'самара', count: '14936' },
  { city: 'ульяновск', count: '1544' },
  { city: 'курган', count: '1785' },
  { city: 'брянск', count: '1841' },
  { city: 'курск', count: '1847' },
  { city: 'липецк', count: '2318' },
  { city: 'уфа', count: '2614' },
  { city: 'красноярск', count: '2671' },
  { city: 'ростов +на дону', count: '2879' },
  { city: 'чебоксары', count: '3013' },
  { city: 'ижевск', count: '3136' },
  { city: 'воронеж', count: '3217' },
  { city: 'санкт петербург', count: '3234' },
  { city: 'тверь', count: '3451' },
  { city: 'новосибирск', count: '3723' },
  { city: 'рязань', count: '3914' },
  { city: 'иркутск', count: '3928' },
  { city: 'казань', count: '4004' },
  { city: 'омск', count: '4279' },
  { city: 'оренбург', count: '4329' },
  { city: 'барнаул', count: '4353' },
  { city: 'ярославль', count: '4881' },
  { city: 'челябинск', count: '5179' },
  { city: 'волгоград', count: '5751' },
  { city: 'тула', count: '5800' },
  { city: 'саратов', count: '5925' },
  { city: 'пенза', count: '6731' },
  { city: 'магнитогорск', count: '684' },
  { city: 'екатеринбург', count: '7224' },
  { city: 'нижний новгород', count: '8179' },
  { city: 'киров', count: '8381' },
  { city: 'пермь', count: '8789' },
  { city: 'тюмень', count: '9346' } ]

I tried this: It displays the same thing that I give to the input, what is the error?
console.log(_.sortBy(collection, 'count'));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krll-k, 2017-05-25
@krll-k

figured out

_.sortBy(collection, function(num){ return num.count*num.count })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question