https://example.com/api/method?NUM=123&STR=abc
null
.value
.- let input = document.getElementsByClassName('form-control');
+ const input = document.querySelector('input.form-control');
letterElement.startsWith('A')
'Andrew'.startsWith('A') // true
'Dmitriy'.startsWith('A') // false
https://vk.com/foaf.php?id=XXXXX
vk.com
const arrBig = [
{ _id: 1, one: 7, two: 5 },
{ _id: 2, one: 6, two: 3 },
{ _id: 3, one: 4, two: 7 },
{ _id: 4, one: 15, two: 2 },
];
const arrSmall = [{ _id: 1, next: 22, gen: 54 }, { _id: 3, next: 6, gen: 3 }];
const key = '_id';
const dictSmall = arrSmall.reduce((acc, c) => {
acc[c[key]] = c;
return acc;
}, {});
const template = { next: 0, gen: 0 };
const addKeys = Object.keys(template);
const result = arrBig.map(item => {
const nuItem = { ...item, ...template };
const addendum = dictSmall[item[key]];
if (addendum) {
addKeys.forEach(key => (nuItem[key] = addendum[key]));
}
return nuItem;
});
/* [
{"_id":1,"one":7,"two":5,"next":22,"gen":54},
{"_id":2,"one":6,"two":3,"next":0,"gen":0},
{"_id":3,"one":4,"two":7,"next":6,"gen":3},
{"_id":4,"one":15,"two":2,"next":0,"gen":0}
] */
ctx
традиционно обозначают не элемент canvas, а взятый из него context (который бывает 2d
, webgl
и др. ctx.width = 100;
ctx.height = 100;
const makeDate = HHMM => {
const [H, M] = HHMM.split(':').map(Number);
const D = new Date();
D.setHours(H);
D.setMinutes(M);
D.setSeconds(0);
return D;
};
const oo = n => n.toString().padStart(2, '0'); // 5 => '05'
const fillTime = (startHHMM, finishHHMM, intervalMinutes) => {
let startDate = makeDate(startHHMM);
let finishDate = makeDate(finishHHMM);
if (startDate > finishDate) { // объекты Date можно так сравнивать
[startDate, finishDate] = [finishDate, startDate]; // поменять местами
}
const dates = [];
const D = new Date(startDate);
while (D <= finishDate) {
dates.push(new Date(D));
D.setMinutes(D.getMinutes() + intervalMinutes);
}
return dates.map(D => [D.getHours(), D.getMinutes()].map(oo).join(':'));
};
console.log(fillTime('15:56', '18:15', 17));
// [ "15:56", "16:13", "16:30", "16:47", "17:04", "17:21", "17:38", "17:55", "18:12" ]
const N = 3;
const delay = ms => new Promise(res => setTimeout(res, ms));
const next = () => {
if (items.length > 0) {
return download(items.shift())
.then(delay(500 + Math.floor(Math.random() * 500))) // случайная пауза между закачками
.then(next);
}
};
const works = Array.from({ length: N }, () =>
Promise.resolve()
.then(next)
.catch(console.error)
);
Promise.all(works).then(() => console.log('All Done'));
[1, 2, 1000, 1001,...]
далее все 100500 элементов больше 1000. const sumTwoSmallestNumbers = arr => {
let a = arr[0];
let b = arr[1];
if (a > b) {
[a, b] = [b, a];
}
for (let i = 2; i < arr.length; i++) {
const v = arr[i];
if (v < a) {
b = a;
a = v;
} else if (v < b) {
b = v;
}
}
return a + b;
};
sumTwoSmallestNumbers([55, 44, 1, 99, 2]); // 3
array()
на []
Создаёт массив с единственным элементом. И присваивает его в$options[$k] = [$row['value']]; // то же самое, что $options[$k] = array($row['value']);
$options[$k]
$arr1 = [ 1, 2, 3 ];
// то же самое, что
$arr1 = array(1, 2, 3);
$arr2 = [
'Habr' => 'QnA',
'Stack' => 'Overflow',
];
// то же самое, что
$arr2 = array(
'Habr' => 'QnA',
'Stack' => 'Overflow',
);
.hidden { display: none; }
document.querySelectorAll('li')
.forEach(li => li.classList.toggle('hidden', !li.querySelector('span')));
для каждого элемента списка устанавливает или снимает класс hidden
, в зависимости от того, найдётся ли span
где-нибудь внутри этого элемента. const tensor = tf.squeeze(result);
const canvas = document.createElement('canvas');
canvas.width = tensor.shape.width
canvas.height = tensor.shape.height
await tf.browser.toPixels(tensor, canvas);
const cat2 = document.createElement('img');
cat2.src = canvas.toDataURL();
$args = [
'name1' => FILTER_SANITIZE_STRING,
'age1' => FILTER_SANITIZE_NUMBER_INT,
'weight1' => FILTER_SANITIZE_NUMBER_FLOAT,
];
$defaults = [
"name1" => "по умолчанию",
"age1" => "по умолчанию",
"weight1" => "по умолчанию",
];
$results = array_merge($defaults, filter_input_array(INPUT_GET, $args));
// вывод
foreach ($results as $name => $value) {
printf('<p>%s: %s</p>', $name, $value);
}
Math.sqrt(N)
// дизель* генератор
const ltSqr = function*(n) {
const limit = Math.min(100, Math.sqrt(n));
let i = 1;
while (i <= limit) {
yield i++;
}
}
// использование
let N = 42;
for (const x of ltSqr(N)) {
console.log(x);
}
// выведет натуральные от 1 до 6
force_original_aspect_ratio
пропорции;ffmpeg -framerate 1/10 -i img%3d.png -i audio.wav \
-vf 'scale=3840:2880:force_original_aspect_ratio=decrease,pad=3840:2880:(ow-iw)/2:(oh-ih)/2,setsar=1' \
-c:v libx264 -crf 14 -r 25 -pix_fmt yuv420p -shortest output.mp4
via https://cdn.jsdelivr.net/npm/sweetalert2@11.4.8