const input = document.querySelector('input');
const num = 100;
input.addEventListener('change', function() {
this.value = (this.value / num | 0) * num;
});
<button data-step="-1">-</button>
<button data-step="+1">+</button>
document.querySelectorAll('[data-step]').forEach(function(n) {
n.addEventListener('click', this);
}, e => input.value = +input.value + e.target.dataset.step * num);
ng-repeat="obj in this.objects | filter: this.searchText as filtered"
ng-if="!filtered.length"
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int main()
{
const int N = 6;
int m[N][N] = { 0 };
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
int x = min(min(i, j), min(N - 1 - i, N - 1 - j));
m[i][j] = N * N + 1 - (i > j
? (N - 2 * x - 2) * (N - 2 * x - 2) + (i - x) + (j - x)
: (N - 2 * x) * (N - 2 * x) - (i - x) - (j - x)
);
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cout << setw(5) << m[i][j];
}
cout << endl;
}
return 0;
}
const inputs = document.querySelectorAll('ol input');
const classes = [...new Set(Array.prototype.flatMap.call(
inputs,
n => [...n.classList]
))];
const classes = Array
.from(inputs, n => Array.from(n.classList))
.flat();
// или
const classes = [].concat.apply(
[],
[].map.call(inputs, n => n.className.split(' '))
);
// или
const classes = [];
for (const n of inputs) {
for (const m of n.classList) {
classes.push(m);
}
}
// или
const classes = [];
for (let i = 0; i < inputs.length; i++) {
for (let j = 0; j < inputs[i].classList.length; j++) {
classes[classes.length] = inputs[i].classList[j];
}
}
// или
const getClasses = (classList, i, n = classList.item(i)) =>
n ? [ n, ...getClasses(classList, -~i) ] : [];
const classes = (function get(i, n = inputs.item(i)) {
return n ? [ ...getClasses(n.classList, 0), ...get(++i) ] : [];
})(0);
class deferred {
constructor() {
this.promise = new Promise(resolve => this.resolve = resolve);
}
then(f) {
this.promise = this.promise.then(f);
}
}
class deferred {
constructor() {
this.callbacks = [];
}
then(f) {
this.callbacks.push(f);
}
resolve(val) {
this.callbacks.reduce((res, f) => f(res), val);
}
}
Не получается обратиться к элементу по его id.
const svgDocument = document.querySelector('object').contentDocument;
const element = svgDocument.querySelector('здесь указываете нужный id или что там вам надо');
function walk($data, $key, &$result) {
foreach ($data as $k => $v) {
if (!array_key_exists($k, $result)) {
$result[$k] = [];
}
if (!is_array($v) || array_keys($v) === range(0, count($v) - 1)) {
$result[$k][$key] = $v;
} else {
walk($v, $key, $result[$k]);
}
}
}
function merge(...$arrays) {
$result = [];
foreach ($arrays as $arr) {
$key = array_keys($arr)[0];
walk($arr[$key], $key, $result);
}
return $result;
}
$result = merge($array1, $array2);
$arr = [
"raz" => [
"qqq" => [ "6" ],
"www" => [ 0 ]
],
"dva" => [
"qqq" => [ 0 ],
"www" => [ 0 ]
]
];
function printArr($arr, $path = '') {
foreach ($arr as $key => $val) {
if (is_array($val)) {
printArr($val, $path."[$key]");
} else {
echo $path."[$val]<br>";
}
}
}
printArr($arr);
Я так понял, вы предлагаете код, который находится в функции setMarkers() перенести в initializeYandexMap(), я прав?
textareaEl.addEventListener('paste', function() {
setTimeout(() => {
this.value = this.value.split('\n').map((n, i) => {
const line = i + 1;
return `${line}. ${n.replace(RegExp(`^${line}\\. `), '')}`;
}).join('\n');
});
});