This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Алгоритм "бегущего окна" | |
// Сложность - O(k*n), где n - длина массива, k - размер искомой последовательности | |
// Найти макс сумму из трех последовательных элементов в массиве | |
const arrInt = [1, 4, 7, 2, 34, 9, 0, 1, 5]; | |
// функция принимает входной массив числел и какое кол-во элементов брать для подмассива | |
function findMaxSummSubArray(arr: number[], k: number) { | |
// сделаем две переменных, одну для хранения суммы, вторая запишем длину входного массива | |
let maxSum: number = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const startUserAuth = () => new Promise(res => setTimeout(res('qazzaq'), 1000)) | |
const userMachine = Machine({ | |
id: 'user', | |
context: { | |
user: null, | |
error: false | |
}, | |
initial: 'idle', | |
states: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useAnimationUnmount = (duration = 300, useNativeDriver = true) => { | |
const [animation] = useState(() => new Animated.Value(1)); | |
const [unmount, setUnmount] = useState(false); | |
const start = useCallback( | |
() => | |
Animated.timing(animation, { | |
toValue: 0, | |
useNativeDriver, | |
duration, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { render } from 'react-dom'; | |
import {Subject, interval} from "rxjs"; | |
import {takeUntil, tap} from "rxjs/operators"; | |
//hook creates subject that will destroy on unmount component | |
const useDestroyedSubject = () => { | |
const subject$ = new Subject(); | |
React.useEffect(() => () => { | |
console.log("destroy subject"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//wrapper for react tree with multi fetch | |
import React, { useState, useEffect, useMemo } from "react"; | |
const apiUrl = `https://jsonplaceholder.typicode.com`; | |
const isValid = (checker, ...args) => | |
args.filter(checker).length === args.length; | |
const fetch = async ({ url, ...options }) => { | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Reactjs custom hook | |
export const useFetch = ({ url, ...options = {} }) => { | |
let [data, setData] = useState(null); | |
const [error, setError] = useState(null); | |
const [status, setStatus] = useState(null); | |
const [loading, setLoading] = useState(true); | |
const ref = useRef(); | |
useEffect( | |
() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Reactive wrapper for Socket.io powered by [email protected] | |
*/ | |
const io = require("socket.io"); | |
const { pipe, of, fromEvent, timer } = require("rxjs"); | |
const { | |
map, | |
merge, | |
takeUntil, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//compose | |
const compose = (...fns) => arg => | |
fns.reduce((composed, fn) => fn(composed), arg); | |
//fetch all urls | |
const fetchUrls = urls => urls.map(url => fetch(url)); | |
//parse body like json | |
const parseResponses = responses => | |
responses.map(response => response.then(data => data.json())); |