const brandsPredicate = s.hasOwnProperty("brands") && s.brands.length > 0
? product => s.brands.includes(product.brand_id)
: () => true;
const paramsPredicate = s.hasOwnProperty("params") && s.params.length > 0
? product => product.hasOwnProperty("params") &&
s.params.some(param => product.params.includes(param))
: () => true;
const result = products.filter(product => brandsPredicate(product) && paramsPredicate(product));
function isPostField(field: string): field is keyof Post {
return field === 'title' || field === 'text';
}
export class SearchingPipe implements PipeTransform {
transform(posts: Post[], search: string, searhcField: string = 'title') {
if (!isPostField(searhcField) || !search.trim()) {
return posts;
}
return posts.filter((post) => {
return post[searhcField]
.toLocaleLowerCase()
.includes(search.toLocaleLowerCase());
});
}
}
function calculateUTCOffsetSeconds(timestamp) {
const date = new Date(timestamp);
const utcTime = date.getUTCHours() * 3600 +
date.getUTCMinutes() * 60 +
date.getUTCSeconds();
const localTime = date.getHours() * 3600 +
date.getMinutes() * 60 +
date.getSeconds();
return localTime - utcTime;
}
console.log(calculateUTCOffsetSeconds(-2208988800000));
type TypeMap = {
string: string;
number: number;
bigint: bigint;
boolean: boolean;
symbol: symbol;
undefined: undefined;
object: object;
function: Function;
};
type TypeName<T> = {
[K in keyof TypeMap]: T extends TypeMap[K] ? K : never;
}[keyof TypeMap];
const evgeniy = <T extends string | number>(x: T) => ({
resultedType: typeof x as TypeName<T>,
});
const freqUpdateInMs = 1000
export default {
data() {
return {
loading: false,
items: {},
timer: null
}
},
mounted() {
const fetchData = () => {
this.$store.commit('setLoading', true)
this.fetchData()
.finally(() => {
this.timer = setTimeout(fetchData, freqUpdateInMs)
this.$store.commit('setLoading', false)
})
}
fetchData()
},
beforeDestroy() {
clearTimeout(this.timer)
}
}
interface TableProps<T extends Record<string, unknown>> {
entities: T[] | null; // тут возможно еще стоит сделать это поле необязательным?
}
const Table = function <T extends Record<string, unknown>>({
entities,
}: TableProps<T>) {
// ...
return (<>
{entities?.map((entity, key) => {
return Object.entries(entity).map(([key, value], index) => {
// ...
});
})}
</>);
}
print(f'Осталось {a} секунд', end='\r')
import time
a = input('Укажите время для таймера в секундах - ')
space = ' ' * len(a)
a = int(a)
while a > 0 :
print(f'Осталось {a} секунд', space, end='\r')
a -= 1
time.sleep(1)
print('Таймер завершен ')
box.addEventListener('mousemove', move, { once: true });
https://developer.mozilla.org/en-US/docs/Web/API/E... eval("/name=" + lastResFind + "/gi")
https://developer.mozilla.org/en-US/docs/Web/JavaS... type ExtractGenerics<T extends readonly unknown[]> = T extends readonly []
? []
: T extends readonly [G<infer V>, ...infer Next]
? [V, ...ExtractGenerics<Next>]
: never;
function unwrap<C extends readonly G<unknown>[]>(containers: C) {
return containers.map(container => container.value) as ExtractGenerics<C>
}