E
E
eldar_web2016-06-26 18:16:17
Node.js
eldar_web, 2016-06-26 18:16:17

How to complete an array (hash) by condition in Ruby?

For example, there is an array:

list = [
{ 'name': 'Аntonello', num: 3 }
{ 'name': 'Sergello', num: 5 }
{ 'name': 'Аntonello', num: 3 }
]

Here the first and third elements match in name and num. How can they be completed into a new array with such data already in the number of copies (with a new count field)?
That is, in our case, there should be such an array:
list = [
{ 'name': 'Аntonello', count: 2 }
{ 'name': 'Sergello', count: 1 }
]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2015-12-01
@all_made

var http = require('http');
var phantom = require('phantom');
var app = http.createServer(function (req,res) {
    res.writeHead(200);
    res.write("Hello world");
    phantom.create(function (ph) {
      ph.createPage(function (page) {
        page.open('http://google.com/', function() {
          console.log('create screen');
          page.render('google.png');
        });
      });
    });
  res.end();
}).listen(8080);
console.log("listening on 8080");

V
vsuhachev, 2016-06-27
@vsuhachev

learn the methods of Enumerable - each, each_with_object, map and others. Without this, you will not move forward.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question