A
A
Alex Wells2015-10-07 18:06:55
JavaScript
Alex Wells, 2015-10-07 18:06:55

How to distribute an array into 100 cells?

Hello. There is an array like

var array = {
  // some data
  'deposits' : {
    {
      'id_user' : 31231232313123,
      'tickets' : 228,
      'chance': 23.34
    },
    {
      'id_user' : 131232312312311,
      'tickets' : 1337,
      'chance': 76.66
    },
  }
};

there may be many deposits. A deposit can have the same user_id. Each deposit has tickets and a chance.
Task: create an array consisting of users, length N (let's take 100 as an example). Users can repeat at least as much, the main thing is that their number should be relative to tickets (well, or chance, it doesn’t matter, they are proportional). How to do it?
UPD: there is an array consisting of several cells (average 2-10). Each cell stores a chance. It is necessary to "stretch" the original cells by exactly 110 cells of the new array, and in the odds ratio.
output example:
var arrayOutput = {
  {
    'user_id' : 3132131213123,
    'chance' : 82.03,
    //other data
  },
  {
    'user_id' : 3132131213123,
    'chance' : 82.03,
    //other data
  },
  {
    'user_id' : 3132131213123,
    'chance' : 82.03,
    //other data
  },
  {
    'user_id' : 3132131213123,
    'chance' : 82.03,
    //other data
  },
  {
    'user_id' : 3132131213123,
    'chance' : 82.03,
    //other data
  },
  {
    'user_id' : 989489482,
    'chance' : 17.97,
    //other data
  },
};

UPD:
Question closed

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question