const key = 'strategy';.const result = arr.filter(function(n) {
return this.has(n[key]);
}, new Set(arr2));const result = arr2.flatMap(((values, n) => values[n] ?? []).bind(
null,
arr.reduce((acc, n) => ((acc[n[key]] ??= []).push(n), acc), {})
));const result = [];
for (const n of arr) {
for (const m of arr2) {
if (m === n[key]) {
result.push(n);
break;
}
}
}const result = [];
for (let i = 0; i < arr.length; i++) {
if (~arr2.indexOf(arr[i][key])) {
result[result.length] = arr[i];
}
}const result = (function get(i, n = arr[i]) {
return n
? [].concat(arr2.includes(n[key]) ? n : [], get(-~i))
: [];
})(0);
{9} пусть будет {4,9}, например. Или {6,9}. Или... Сами решайте, сколько их должно быть, вам виднее.a-z, а a-f.
const baseURL = 'https://iss.moex.com//iss/history/engines/stock/markets/index/securities/RGBITR.json';
const params = new URLSearchParams([
[ 'sort_order', 'desc' ],
[ 'iss.meta', 'off' ],
[ 'iss.only', 'history' ],
[ 'history.columns', 'TRADEDATE,CLOSE' ],
]);
fetch(`${baseURL}?${params}`)
.then(r => r.json())
.then(r => {
new Chart(document.querySelector('#chart'), {
type: 'line',
data: {
labels: r.history.data.map(n => n[0]),
datasets: [ {
label: 'hello, world!!',
data: r.history.data.map(n => n[1]),
} ],
},
});
});fetch(`${baseURL}?${params}`)
.then(r => r.json())
.then(({ history: { data } }) => {
chart.data.labels = data.map(n => n[0]);
chart.data.datasets[0].data = data.map(n => n[1]);
chart.update();
});
const chart = new Chart(document.querySelector('#chart'), {
type: 'line',
data: {
labels: [],
datasets: [ {
label: 'hello, world!!',
data: [],
} ],
},
});
<slot name="placeholder"></slot><template #placeholder>
<option value="" disabled>давай, выбирай</option>
</template>
const container = document.body;
const key = 'number';
const attr = `data-${key}`;
const attrSelector = `[${attr}]`;container.addEventListener('click', function(e) {
const value = e.target.closest(attrSelector)?.dataset[key];
if (value) {
this.querySelectorAll(`[${attr}="${value}"]`).forEach(n => n.remove());
}
});const elems = [...container.querySelectorAll(attrSelector)];
const onClick = ({ currentTarget: { attributes: { [attr]: { value } } } }) =>
elems.length -= elems.reduce((acc, n, i, a) => (
a[i - acc] = n,
acc + (n.getAttribute(attr) === value && !n.replaceWith())
), 0);
elems.forEach(n => n.addEventListener('click', onClick));
watch: {
alias: {
immediate: true,
handler: 'getArticles',
},
},
function haveSameValues(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
}
const count = new Map;
arr1.forEach(n => count.set(n, -~count.get(n)));
arr2.forEach(n => count.set(n, ~-count.get(n)));
for (const n of count.values()) if (n) {
return false;
}
return true;
}haveSameValues(
[ 'hello, world!!', 0, 0, 0, 1, 1, false, false ],
[ false, false, 1, 1, 0, 0, 0, 'hello, world!!' ]
) // true
haveSameValues(
[ 1, 2, 3 ],
[ 3, 2, 2 ]
) // false
haveSameValues(
[],
[]
) // true
const arr = Array.from(
new Set(Array.from(document.querySelectorAll('.shop_name'), n => n.innerText)),
n => ({ name: n })
);const arr = Object.values(Array.prototype.reduce.call(
document.getElementsByClassName('shop_name'),
(acc, { textContent: name }) => (acc[name] ??= { name }, acc),
{}
));
function onClick({ currentTarget: t }) {
const className = t.dataset.activeClass;
document.querySelector(`.${className}`)?.classList.remove(className);
t.classList.add(className);
}
Vue.directive('active-class', {
bind(el, binding) {
el.dataset.activeClass = binding.value;
el.addEventListener('click', onClick);
},
update(el, binding) {
el.dataset.activeClass = binding.value;
},
unbind(el) {
delete el.dataset.activeClass;
el.removeEventListener('click', onClick);
},
});<div v-active-class="'buy-voucher__amount_selected'">
<input v-active-class="'buy-voucher__amount_selected'">
router-view не забыли добавить?
- arr = [ 1, 2, 3, 4, 5, 6, 7, 8 ]
mixin xxx(arr, method, ...args)
- newArr = arr[method](...args)
p= newArr
+xxx(arr, 'slice', 2, 5)
+xxx(arr, 'filter', n => n & 1)- arr = [ 1, 2, 3, 4, 5, 6, 7, 8 ]
mixin xxx(arr)
ul
each n in arr
li= n
+xxx(arr.slice(-3))
+xxx(arr.filter(n => !(n % 3)))
React.useEffect(() => {
fetch(props.link)
.then(r => r.json())
.then(setItems);
}, [ props.link ]);