#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');
});
});
Элемент - представленный в примере - это FileInput (кликать нужно на него, что бы вызвать диалог выбора файлов)
const imgs = document.querySelectorAll('img[src*="/test/"]');это не в dom, а в строке
const div = document.createElement('div');
div.innerHTML = str;
const imgsStr = ''.concat(...[].map.call(
div.querySelectorAll('img[src*="/test/"]'),
n => n.outerHTML
));const imgsStr = Array
.from(
new DOMParser().parseFromString(str, 'text/html').querySelectorAll('img[src*="/test/"]'),
n => n.outerHTML)
.join('');const imgsStr = Array.prototype.reduce.call(
document.createRange().createContextualFragment(str).querySelectorAll('img[src*="/test/"]'),
(acc, n) => acc + n.outerHTML,
''
);мне нужно удалить из этой строки все картинки, которые...
const div = document.createElement('div');
div.innerHTML = str;
const imgs = div.querySelectorAll('img[src*="/test/"]');
for (let i = 0; i < imgs.length; i++) {
imgs[i].outerHTML = '';
}
str = div.innerHTML;const { body } = new DOMParser().parseFromString(str, 'text/html');
body.querySelectorAll('img[src*="/test/"]').forEach(n => n.remove());
str = body.innerHTML;const fragment = document.createRange().createContextualFragment(str);
for (const n of fragment.querySelectorAll('img[src*="/test/"]')) {
n.parentNode.removeChild(n);
}
str = Array.from(fragment.childNodes, n => n.outerHTML || n.nodeValue).join('');
Как программно получить индексы Ряда и Ячейки для строки кода
this.showPillarHandler(p.data[индекс Ряда].data[индекс Ячейки]) ?
showMachine={this.showPillarHandler}.showShelfMachine={showMachine}.showPlaceMachine={showShelfMachine}.onClick={() => showPlaceMachine(seat)}.
computed: {
groupedPosts() {
return this.posts.reduce((acc, n) => {
(acc[n.category] = acc[n.category] || []).push(n);
return acc;
}, {});
},
},При нажатии на название категории хочу выводить посты и соответствующего массива.
categories() {
return Object.keys(this.groupedPosts);
},data: () => ({
activeCategory: null,
...<button
v-for="n in categories"
v-text="n"
:class="{ active: n === activeCategory }"
@click="activeCategory = n"
></button><div v-if="activeCategory">
<div v-for="n in groupedPosts[activeCategory]" class="post">
...
Я тут начинаю изучать php с фреймворка yii2