π³
This file contains hidden or 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 {useState, useEffect, Component} from 'react' | |
const ErrorBlock = ({error: e, onReload}) => ( | |
<div> | |
<div role="alert"> | |
There was an rejected: {e?.message && <pre style={{whiteSpace: 'normal'}}>{e.message}</pre>} | |
</div> | |
<button onClick={onReload}>Reload page</button> | |
</div> | |
) |
This file contains hidden or 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 { asyncParallel } from './asyncParallel' | |
const fakedFetch = (timeout: number) => new Promise((resolve) => setTimeout(() => resolve(timeout), timeout * 1000)) | |
describe('fakedFetch', () => { | |
test('should retun Promise', () => { | |
expect(fakedFetch(1) instanceof Promise).toBeTruthy() | |
}) | |
test('should asyncronously retun value after delay', async () => { |
This file contains hidden or 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 { equalChunks, getChunkIndexes, extractByIndexes, ResultType } from './equalChunks' | |
describe('equalChunks', () => { | |
const helpers = { | |
sum: (arr: number[]) => arr.reduce((a, b) => a + b), | |
have3equalChunks: (arr: ResultType) => arr.every((item) => helpers.sum(item) === helpers.sum(arr[0])), | |
} | |
test('should return null on empty array', () => { | |
expect(typeof equalChunks).toBe('function') |
This file contains hidden or 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 { maxSubArray, addToSet } from './max-sub-array.airbnb' | |
describe('MaxSubArray', () => { | |
let arr = [] | |
test('should return on empty array', () => { | |
expect(maxSubArray(arr)).toBeUndefined() | |
}) | |
test('should work on array.length === 1', () => { |
This file contains hidden or 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
export const compose = (...fns) => (...args) => | |
fns.reduceRight((args, fn) => fn(...(Array.isArray(args) ? args : [args])), args) | |
export const composeRecursive = (...fns) => { | |
const last = fns.pop() | |
if (!fns.length) return (...args) => last(...args) | |
const prev = fns.pop() | |
fns.push((...args) => { | |
let res = last(...args) |