const {JSDOM} = require('jsdom');
const group = (str) => {
const {document} = new JSDOM(str.replace(/(\[|\])/g, (_, s) => ({
'[': '<',
']': '>'
})[s])).window;
return [...document.body.querySelectorAll('*')].reduce((acc, elem) => {
acc[elem.tagName] = [...elem.childNodes].reduce((str, elem) => {
return str + (elem.nodeType === document.TEXT_NODE ? elem.textContent : '');
}, '');
return acc;
}, {});
};
console.log(group('[m]Галифакс ([i]город в Канаде[/i])[/m]'));
console.log(group('[m][p]г.[/p] Хадалык ([i]Синьцзян-Уйгурский[c] авт.[/c] р-н, КНР[/i])[/m]'));
function bang() {
try {
({}).a();
} catch(e) {
e.message = "Just thr" + "ow like this!";
(function* () {})()['thr' + 'ow'](e);
}
}
function sum(args, func) {
const result = [];
const length = Math.max(...args.map((item) => item.length));
for (let i = 0; i < length; ++i) {
const arr = args.map((item) => item[i]).filter(Boolean);
const maxLength = Math.max(...arr.map((item) => item.length));
result.push([]);
for (let j = 0; j < maxLength; ++j) {
result[i].push(arr.map((item) => item[j]).filter(Number).reduce(func));
}
}
return result;
}
/* сложить */
sum([arr1, arr2, arr3], (acc, curr) => acc + curr);
/* умножить */
sum([arr1, arr2, arr3], (acc, curr) => acc * curr);
const result = data.reduce((acc, curr) => {
const {category, family, symbol, id} = curr;
acc.category[category] = acc.category[category] || {family: {}};
acc.category[category].family[family] = acc.category[category].family[family] || {symbol: {}};
acc.category[category].family[family].symbol[symbol] = acc.category[category].family[family].symbol[symbol] || {id: []};
acc.category[category].family[family].symbol[symbol].id.push(id);
return acc;
}, {category: {}});
const str = 'У Миши 2 яблока';
const newStr = str.replace('Миши', 'Саши');
и зачем здесь jquery? var bod = document.getElementById('main_info');
var elem = bod.querySelector('#one');
for (var i = 0; i => fields; i++) {
for (var i = 0; i < fields.length; i++) {
? func1() {
return this.setJson();
}
async func2() {
let q = await this.func1();
return q;
}
let arr = [ 'nameOneItem' : 'Name one', 'nameTwoItem' : 'Name two' ];
let arr = [
'Name one',
'Name two'
];
let obj = {
'nameOneItem' : 'Name one',
'nameTwoItem' : 'Name two'
};
let out = '';
let arr = Object.values(obj);
for (let i = 0; i < arr.length; i++ ) {
out += '<span>' + arr[i] + '</span>';
}
function isInInterval(start, end) {
return area.value >= start && area.value <= end;
}
const values = floors.value === 1 ? [
[-Infinity, 120, 1.26],
[120.001, 140, 1.24],
[140.001, 160, 1.23],
[160.001, 200, 1.22],
[200.001, 260, 1.2],
[260.001, 300, 1.19]
] : floors.value === 2 || floors.value === 3 ? [
[100, 130, 1.3],
[130.001, 160, 1.27],
[160.001, 200, 1.24],
[200.001, 300, 1.22]
] : [];
const [,, result] = values
.find(([start, end]) => isInInterval(start, end)) || [,, 1];
console.log(result);
const arr = [
"google.com|toster.ru|RU|120|222",
"google.com|toster.ru|RU|120|222",
"google.com|toster.ru|UA|120|222",
"google.com|toster.ru|BG|120|222",
"google.com|yandex.ru|IT|777|843"
];
const result = arr.reduce((acc, curr) => {
const [a, b, geo, c, id] = curr.split('|');
const elem = acc.find(({value}) => value === id);
if (elem) {
if (!elem.items.includes(geo)) {
elem.items.push(geo);
}
} else {
acc.push({
items: [geo],
elems: [a, b, c],
value: id
});
}
return acc;
}, []).map(({items, elems: [a, b, c], value}) => [a, b, items.join('+'), c, value].join('|'));
function isSame(a, b) {
return a.every((item, i) => item === b[i]);
}
arr.reduce((acc, curr) => {
if (acc.every((item) => !isSame(item, curr))) {
acc.push(curr);
}
return acc;
}, []);