new MutationObserver((mutations, observer) => {
if (mutations[0].target.classList.contains('интересующий-вас-класс')) {
observer.disconnect();
typed.start();
}
}).observe(элементНаличиеКлассаУКоторогоНадоОтследить, { attributes: true });
const stars = (n) => {
for (let r = 4; r >= 0; r--) {
const shift = r * 5;
const bits = (n & 31 << shift) >> shift;
console.log(Array(5).fill('').map((_, i) => bits & 1 << i ? '*' : ' ').reverse().join(''));
}
}
stars(0x1e8fa10); // P
stars(0x457e31); // A
****
* *
****
*
*
*
* *
*****
* *
* *
document.querySelector('.case-print')
<svg ...>
<path class="area" data-id="1" d="..." />
<path class="area" data-id="2" d="..." />
</svg>
type CreatureBasis = {
People: {
child: {
age: number;
school: string;
};
adult: {
age: number;
height: number;
weight: number;
};
};
Animal: {
fish: {
waterBody: string;
};
cat: {
catchMouses: boolean;
};
};
};
type Creature = {
[K0 in keyof CreatureBasis]: {
[K1 in keyof CreatureBasis[K0]]: {
type: K0;
subtype: K1;
params: CreatureBasis[K0][K1];
};
}[keyof CreatureBasis[K0]];
}[keyof CreatureBasis];
const $container = $('.promo__cats');
$container.append(...$container
.children()
.get()
.map(n => [ n, +$('.promo__price', n).text().replace(/\D/g, '') ])
.sort((a, b) => a[1] - b[1])
.map(n => n[0])
);
const createItem = obj => ({ key: `${obj.name}-${obj.id}`, title: obj.name });
const result = Object.values(columnList.reduce((acc, n) => {
(acc[n.table.id] ??= {
...createItem(n.table),
children: [],
}).children.push(createItem(n));
return acc;
}, {}));
T[keyof T]
и передаёшь interface IUser {
name: string;
role: IRole;
}
string | IRole
.type Extractor<T, X> = (entry: T) => X;
const groupBy = <T, X>(
collection: T[],
mapper: Extractor<T, X>
): Map<X, T[]> => collection.reduce((accumulator, entry) => {
const key = mapper(entry);
if (accumulator.has(key)) {
accumulator.get(key)!.push(entry);
return accumulator;
}
accumulator.set(key, [entry]);
return accumulator;
}, new Map<X, T[]>());