[ 1, 2 ], например. Или [ 5, 6, 8, 9 ].const range = ([...arr]) => arr
.sort((a, b) => a - b)
.reduce((acc, n, i, a) => (
(n === a[i - 1] + 1) || acc.push([ n ]),
acc[acc.length - 1][1] = n,
acc
), [])
.map(([ a, b ]) => a === b ? a : `${a}-${b}`)
.join(', ');const range = arr => ''.concat(...arr
.slice()
.sort((a, b) => a - b)
.reduce((acc, n, i, a) => (
n !== a[i - 1] + 1 && acc.push(i ? `, ${n}` : n),
n === a[i - 1] + 1 && n !== a[i + 1] - 1 && acc.push(`-${n}`),
acc
), [])
);
function randomCall(items) {
const max = items.reduce((acc, n) => acc + n.ratio, 0);
return function(...args) {
const val = Math.random() * max;
for (let sum = 0, i = 0; i < items.length; i++) {
sum += items[i].ratio;
if (sum > val) {
return items[i].func.apply(this, args);
}
}
};
}const func = randomCall([
{ func: func1, ratio: 1 },
{ func: func2, ratio: 2 },
{ func: func3, ratio: 3 },
{ func: func4, ratio: 4 },
]);
location = /api/servertime {
access_log off;
rewrite ^ /index.php break;
include fastcgi.conf;
fastcgi_pass php;
}location ~ \.php$location ~ \.php$ {
if ($request_uri ~ "^/api/servertime") {
access_log off;
}
include fastcgi.conf;
fastcgi_pass php;
}access_log путь [формат [if=условие]];map $request_uri $loggable {
default 1;
~^/api/servertime 0;
}
server {
# ...
root /var/www/lumen/public;
try_files $uri $uri/ /index.php$is_args$args;
# ...
location ~ \.php$ {
access_log /var/log/nginx/access.log combined if=$loggable;
include fastcgi.conf;
fastcgi_pass php;
}
}