ctx.clearRect(0 , 0 , ctx.canvas.width , ctx.canvas.height)
$mysql = new mysqli("localhost", "root", "root", "medixer");
$mysql->set_charset("utf8");
$stmt = $conn->prepare("INSERT INTO `users` (`login_user`, `name`, `password`, `dob`, `region`, `telephone`, `email`) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssss", $login, $name, $password, $dob, $region, $telephone, $email);
$stmt->execute();
$mysql->close();
function spread(q, volumes) {
const total = volumes.reduce((a, b) => a + b);
const result = volumes.slice().fill(0);
const target = volumes.map((v) => q * v / total);
while (q--) {
const demand = result.map((v, i) => target[i] - v);
const minIndex = demand.indexOf(Math.max(...demand));
result[minIndex]++;
}
return result;
}
spread(4, [1, 10, 3]) // [0, 3, 1]
spread(9, [1, 10, 3]) // [1, 6, 2]
spread(1, [10, 10, 10]) // [1, 0, 0] - слева направо при равных
spread(33, [10, 10, 10]) // [11, 11, 11] - переполняются тоже одинаково
spread(4, [2, 3, 1]) // [ 1, 2, 1 ]
spread(5, [2, 3, 1]) // [ 2, 2, 1 ]
spread(9, [2, 3, 1]) // [ 3, 5, 1 ]
index2 - index1 + 1
и заменить его фразой replacement.[...arr.reduce((acc, c) => (acc.set(c, (acc.get(c) ?? 0) + 1), acc), new Map()).entries()]
.sort((a, b) => b[1] - a[1]).map((el) => el[0])
Собрать словарь (значение: счётчик)
, из него массив пар [key, value]
отсортировать по убыванию второго; оставить только первые. const areEqual = (arrA, arrB) => {
if (arrA.length !== arrB.length) return false;
const a = arrA.slice().sort(), b = arrB.slice().sort();
return a.every((el, i) => el === b[i]);
}
const areEqual = (arrA, arrB) => {
if (arrA.length !== arrB.length) return false;
const a = arrA.slice(), b = arrB.slice();
while (a.length) {
const i = b.indexOf(a.pop());
if (-1 === i) return false;
b.splice(i, 1);
}
return true;
}
private isThumbsCollision(): boolean {
const prop = [
{size: 'width', side: 'right'},
{size: 'height', side: 'top'},
][+this.settings.isVertical];
return this.to.tooltip.element.getBoundingClientRect()[prop.size]
>= this.to.element.getBoundingClientRect()[prop.side]
- this.from.element.getBoundingClientRect()[prop.side];
}
const stars = (n) => {
for (let r = 4; r >= 0; r--) {
const shift = r * 5;
const bits = (n & 31 << shift) >> shift;
console.log(Array(5).fill('').map((_, i) => bits & 1 << i ? '*' : ' ').reverse().join(''));
}
}
stars(0x1e8fa10); // P
stars(0x457e31); // A
****
* *
****
*
*
*
* *
*****
* *
* *
class Name1 {
static method1() {
console.log(1);
}
}
class Name2 {
method2() {
Name1.method1();
}
}
const N2 = new Name2();
N2.method2()
canvas
: сжать по вертикали и повернуть на 45°. Теперь, если рисовать квадраты — получатся ромбики!document.getElementsByClassName('xxx')[0].click();
s
попадает элемент span
, а не значение.const elements = { // сюда складывать элементы
list: [],
btn: [],
};
function pushItem() {
const div = document.createElement('div'); // временный родитель
div.innerHTML = `<div class="listItem">${items.pop()}<button class="delete">Отменить</button></div>`;
elements.list.push(div.querySelector('.listItem');
elements.btn.push(div.querySelector('.delete');
// перенести из временного в постоянный
while (div.childNodes.length) { // с запасом: вдруг там несколько элементов
list.appendChild(div.childNodes[0];
}
};