type union = 'a' | 'b' | 'c'
type I = {
someOtherField?: number;
} & Record<union, any>;
// result:
interface I {
someOtherField?: number;
a: any
b: any
c: any
}
someOtherField
из примера), то можно обойтись просто Record<union, string>
. Как-то так:type I = Record<union, any>;
Крайне любопытен с точки зрения визуальной составляющей.
Мне бы хотелось понимать, посредством каких технологий он был сделан.
observable$.pipe(
switchMap((result) => {
return of(result).pipe(.....)
})
).subscribe(...)
std::string encodeString(std::string str) {
std::string result = "";
int count = 0;
int len = str.length();
for (int i = 0; i < len; i++) {
count++;
if (i == len - 1 || str[i] != str[i + 1]) {
result += str[i] + std::to_string(count);
count = 0;
}
}
return result;
}
const getDuplicates = (arr, key) => Array
.from(arr.reduce((acc, { [key]: n }) => acc.set(n, -~acc.get(n)), new Map))
.filter(n => n[1] > 1)
.map(n => n[0]);
const duplicates = getDuplicates(arr, 1);
const getDuplicates = (arr, key = n => n) => Array
.from(arr.reduce((acc, n) => (n = key(n), acc.set(n, acc.has(n))), new Map))
.reduce((acc, n) => (n[1] && acc.push(n[0]), acc), []);
const duplicates = getDuplicates(arr, n => n[1]);
const getDuplicates = arr =>
[...arr.reduce((acc, n) => (
acc[+acc[0].has(n)].add(n),
acc
), [ new Set, new Set ])[1]];
const duplicates = getDuplicates(arr.map(n => n[1]));
Не поможет ли lodash?
const duplicates = _(arr)
.map(n => n[1])
.groupBy()
.filter(n => n.length > 1)
.map(n => n[0])
.value();
methods: {
weekDay(date) {
return new Date(date).toLocaleString('ru-RU', { weekday: 'short' });
},
titleDate(dates) {
return dates
.map(n => new Date(n).toLocaleString('ru-RU', {
weekday: 'short',
month: 'short',
day: 'numeric',
}))
.join(' - ');
},
},
<v-date-picker
:weekday-format="weekDay"
:title-date-format="titleDate"
/>
<select id="event"></select>
<select id="dates"></select>
const events = [
{ name: '...', dates: [ ... ] },
{ name: '...', dates: [ ... ] },
...
];
const eventEl = document.querySelector('#event');
const datesEl = document.querySelector('#dates');
eventEl.innerHTML = events
.map((n, i) => `<option value="${i}">${n.name}</option>`)
.join('');
eventEl.addEventListener('change', function() {
datesEl.innerHTML = events[this.value].dates
.map(n => `<option>${n}</option>`)
.join('');
});
eventEl.dispatchEvent(new Event('change'));
created() { this.tagsAsArray.forEach((item) => { this.editState[item] = false; }); },
Vue cannot detect property addition or deletion.
created() {
this.editState = Object.fromEntries(this.tagsAsArray.map(n => [ n, false ]));
},
@onClick="editTagName"
|| to.name === 'Authorization'
в beforeEach в if. const setOptions = (el, options, placeholder) =>
el.innerHTML =
`<option hidden selected value="">${placeholder}</option>` +
options.map(n => `<option>${n}</option>`).join('');
Object
.entries({ defaultTest, systemTest })
.flatMap(([ k, { references, ...n } ]) => references.map(m => ({
...m,
...n,
[k]: true,
})))
Object
.entries({ defaultTest, systemTest })
.map(([ k, v ]) => v.map(({ references, ...n }) => references.map(m => ({
...m,
...n,
[k]: true,
}))))
.flat(2)