const count = matrix.flat().reduce((acc, n) => (acc[n] = -~acc[n], acc), {});
const count = {};
for (const row of matrix) {
for (const n of row) {
if (!count.hasOwnProperty(n)) {
count[n] = 0;
}
count[n]++;
}
}
data: () => ({
selected: [],
}),
methods: {
key: (x, y) => `${y}.${x}`,
select({ buttons, target: { dataset: { key } } }) {
if (buttons) {
const index = this.selected.indexOf(key);
if (index !== -1) {
this.selected.splice(index, 1);
} else {
this.selected.push(key);
}
}
},
},
<table>
<tr v-for="y in 10">
<td
v-for="x in 10"
@mousedown="select"
@mouseover="select"
:data-key="key(x, y)"
:class="{ selected: selected.includes(key(x, y)) }"
>{{ key(x, y) }}</td>
</tr>
</table>
data: () => ({
items: [...Array(10)].map(() => Array(10).fill(false)),
}),
methods: {
select(row, index, e) {
if (e.buttons) {
this.$set(row, index, !row[index]);
}
},
},
<table>
<tr v-for="(row, y) in items">
<td
v-for="(cell, x) in row"
@mousedown="select(row, x, $event)"
@mouseover="select(row, x, $event)"
:class="{ selected: cell }"
>{{ y + 1 }}.{{ x + 1 }}</td>
</tr>
</table>
const chunked = (data, chunkSize) =>
Array.prototype.reduce.call(
data,
(acc, n, i) => (
i = i / chunkSize | 0,
(acc[i] = acc[i] || []).push(n),
acc
),
[]
);
console.log(chunked([...Array(10).keys()], 3));
console.log(chunked('ABCDEFG', 2));
console.log(chunked(document.querySelectorAll('img'), 5));
const data = [
{
floors: [ 1 ],
limits: [
{ f: 1.26, max: 120 },
{ f: 1.24, max: 140 },
{ f: 1.23, max: 160 },
{ f: 1.22, max: 200 },
{ f: 1.20, max: 260 },
{ f: 1.19, max: 300 },
],
},
{
floors: [ 2, 3 ],
limits: [
{ f: 1.00, max: 100, excludeMax: true },
{ f: 1.30, max: 130 },
{ f: 1.27, max: 160 },
{ f: 1.24, max: 200 },
{ f: 1.22, max: 300 },
],
},
];
const d = data.find(n => n.floors.includes(floors.value));
if (d) {
const v = area.value;
console.log((d.limits.find(n => n.excludeMax ? n.max > v : n.max >= v) || { f: 1 }).f);
}
const ﹩ = document.querySelector.bind(document) // вау, почти jQuery! с одной строчки!
// Кто-то может повестись и знатно вынести себе моск:)
﹩('#nav-trigger').onclick =ௐ=> {
﹩('#menu-navigation').classList.add('active');
﹩('#menu-close').classList.add('active');
}
HTMLElement.prototype.addClass = function(className) { this.classList.add(className) }
﹩('#menu-navigation').addClass('active');
const ﹩ = selector => (list => list.length > 1 ? [...list] : list[0])(document.querySelectorAll(selector))