const a = {};
const b = {};
a.b = b;
b.a = a;
cloneDeep(a); // бесконечный цикл
let cities = [];
function myGame() {
const input = document.getElementById('input_city');
const output = document.getElementById('output_city');
//Если массив пустой добавим 1е слово без всяких проверок.
if (!cities.length) {
console.log('Верно идем дальше');
cities.push(input.value);
input.value = ''
console.log(cities)
return
}
const lastCity = cities[cities.length - 1];
const lastLetter = lastCity[lastCity.length - 1];
const firstLetter = input.value.substr(0, 1); // первая буква слова
if (lastLetter.toLowerCase() === firstLetter.toLowerCase()) {
console.log('Верно идем дальше');
cities.push(input.value);
input.value = ''
} else {
console.log('Херня, давай сначала.')
}
console.log(cities);
}
const arr = []; // создали массив
arr.push = function() { // перезаписываем конкретно его push
Array.prototype.push.apply(this, arguments); // вызвали оригинальный push со всеми аргументами
// тут делаем еще что-то
};
function replaceText(node, replacer) {
if (node.nodeType === Node.ELEMENT_NODE) {
node.childNodes.forEach(n => replaceText(n, replacer));
} else if (node.nodeType === Node.TEXT_NODE) {
node.textContent = replacer(node.textContent);
}
}
replaceText(document.body, str => str.replace(/\d/g, 'hello, world!!'));
function replaceText(node, replacer) {
const iter = document.createNodeIterator(node, NodeFilter.SHOW_TEXT);
for (let n = null; n = iter.nextNode();) {
n.nodeValue = replacer(n.nodeValue);
}
}
const merge = (...arrs) =>
Array.from(
{ length: Math.max(...arrs.map(n => n.length)) },
(_, i) => Object.assign({}, ...arrs.map(n => n[i]))
);
const arr = merge(arr1, arr2);
const merge = (...arrs) =>
arrs.reduce((acc, n) => (
n.forEach((m, i) => Object.assign(acc[i] ??= {}, m)),
acc
), []);
// main.js
export default {
title: "sun",
subtitle: "earth",
r: "mars"
}
<h1></h1>
<h2></h2>
<p></p>
//index.js
import data from './main.js';
// Пишем функцию, чтобы не менять каждый элемент вручную
const changeHtmlText = (querySelector, data) => {
const $element = document.querySelector(querySelector);
$element.textContent = data
}
changeHtmlText("h1", data.title);
changeHtmlText("h2", data.subtitle);
changeHtmlText("p", data.r);
main
section
заголовок
article
заголовок
описание
ссылка
article
заголовок
описание
ссылка
$text=preg_replace('~\[CODE\](.*?)\[/CODE\]~si', '<pre>$1</pre>',$text);