const blocks = document.getElementsByClassName('block');
const stats = [];
for(block of blocks) {
const size = block.getElementsByClassName('item').length;
stats.push(size);
}
alert(stats);
<?php
$total = 400;
$count = 45;
$numbers = [];
do {
$random = mt_rand(1, 1000);
if (!array_key_exists($random, $numbers)) {
$numbers[$random] = $random;
}
} while (sizeof($numbers) < $count);
$sum = array_sum($numbers);
foreach ($numbers as $k => $v) {
$numbers[$k] = $total * $v / $sum;
}
print_r($numbers);
print_r(array_sum($numbers));
Array
(
[192] => 3.0298248382515
[993] => 15.669875335332
[291] => 4.592078270475
[695] => 10.967334700963
[718] => 11.330282468045
[386] => 6.0912103519015
[400] => 6.3121350796907
[751] => 11.851033612119
[507] => 8.000631213508
[206] => 3.2507495660407
[933] => 14.723055073379
[872] => 13.760454473726
[711] => 11.21982010415
[890] => 14.044500552312
[224] => 3.5347956446268
[659] => 10.39924254379
[899] => 14.186523591605
[67] => 1.0572826258482
[948] => 14.959760138867
[976] => 15.401609594445
[140] => 2.2092472778917
[399] => 6.2963547419915
[492] => 7.7639261480196
[812] => 12.813634211772
[572] => 9.0263531639577
[561] => 8.8527694492662
[834] => 13.160801641155
[534] => 8.4267003313871
[873] => 13.776234811425
[143] => 2.2565882909894
[768] => 12.119299353006
[342] => 5.3968754931356
[354] => 5.5862395455263
[202] => 3.1876282152438
[716] => 11.298721792646
[811] => 12.797853874073
[701] => 11.062016727158
[987] => 15.575193309137
[669] => 10.557045920783
[513] => 8.0953132397033
[706] => 11.140918415654
[242] => 3.8188417232129
[440] => 6.9433485876598
[171] => 2.6984377465678
[48] => 0.75745620956288
)
400
<?php
// это наш массив из базы, но для примера задаю данные в пхп массиве
$data = array(
array('id' => 1, 'pid' => 0, 'name' => '1'),
array('id' => 2, 'pid' => 1, 'name' => '1.1'),
array('id' => 3, 'pid' => 2, 'name' => '1.1.1'),
array('id' => 4, 'pid' => 0, 'name' => '2'),
array('id' => 5, 'pid' => 0, 'name' => '3'),
array('id' => 6, 'pid' => 5, 'name' => '3.1'),
array('id' => 7, 'pid' => 5, 'name' => '3.2'),
);
//теперь создаем массив в виде дерева
$tree = array();
foreach ($data as $row) {
$tree[(int) $row['pid']][] = $row;
}
//ну и рекурсивная функция для вывода дерева
function treePrint($tree, $pid=0) {
if (empty($tree[$pid]))
return;
echo '<ul>';
foreach ($tree[$pid] as $k => $row) {
echo '<li>';
echo $row['name'];
if (isset($tree[$row['id']]))
treePrint($tree, $row['id']);
echo '</li>';
}
echo '</ul>';
}
//вызов функции
treePrint($tree);
const fetch = require('node-fetch');
let names = ['iliakan', 'remy', 'jeresig'];
let requests = names.map(name => fetch(`https://api.github.com/users/${name}`).then(response => response.json()));
(async () => {
const users = await Promise.all(requests);
users.forEach(user => {
console.log(user.name);
})
})();
<?php
$q = $db->prepare("SELECT * FROM request_journal WHERE addres = ? AND kv = ? ORDER BY date DESC");
$q->execute([$this->house, $this->flat]);
$data = $q->fetchAll();
print_r($data);
let bbb = (function () {
start = function() {
console.log('222');
};
})();
start();
function bbb() {
function start() {
console.log('222');
}
return start;
}
const closure = bbb();
closure();