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
type KV = Record<string, any>; | |
type MyParameters<F> = F extends (...args: infer P) => unknown | |
? P extends [infer A] | |
? A extends KV | |
? KV | |
: [A] | |
: P | |
: never; |
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
/** | |
* denseRank({ | |
* array: [ | |
* {name: 'a', age: 20}, | |
* {name: 'b', age: 5}, | |
* {name: 'c', age: 20}, | |
* {name: 'd', age: 75}, | |
* {name: 'e', age: 21}, | |
* ], | |
* column: 'age', |
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
/** | |
* rank({ | |
* array: [ | |
* {name: 'a', age: 20}, | |
* {name: 'b', age: 5}, | |
* {name: 'c', age: 20}, | |
* {name: 'd', age: 75}, | |
* {name: 'e', age: 21}, | |
* ], | |
* column: 'age', |
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 { useState } from 'react' | |
export const useStep = < | |
T extends { | |
[step: string]: string | |
} | |
>({ | |
steps, | |
initialStep, | |
}: { |
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
/** | |
* cumulativeSumObjects({ | |
* 20200101: {a: 1, b: 2, c: 3}, | |
* 20200102: {b: 1, c: 2, d: 3}, | |
* 20200103: {c: 1, d: 2, e: 3}, | |
* }) | |
* => { | |
* 20200101: {a: 1, b: 2, c: 3, d: 0, e: 0}, | |
* 20200102: {a: 1, b: 3, c: 5, d: 3, e: 0}, | |
* 20200103: {a: 1, b: 3, c: 6, d: 5, e: 3}, |
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
/** | |
* sumObjects([ | |
* {a: 1, b: 2}, | |
* {b: 3, c: 4}, | |
* ]) | |
* => {a: 1, b: 5, c: 4} | |
*/ | |
const sumObjects = ( | |
objects: Record<string, number>[] | |
): Record<string, number> => |
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
/** | |
* Returns an array of all combinations of elements from all arrays. | |
* | |
* @examples | |
* combinations([1], [2, 3], [4, 5, 6]) | |
* => "[[1,2,4],[1,2,5],[1,2,6],[1,3,4],[1,3,5],[1,3,6]]" | |
*/ | |
export const combinations = <T extends unknown>(...arrays: T[][]): T[] => { | |
const result: T[] = [] | |
const _combinations = (n: number, current: T[]) => { |
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 calcPieChartValues = (values, numDegits = null) => { | |
const totalValue = values.reduce((a, c) => a + c); | |
const deg2rad = (deg) => deg * Math.PI / 180; | |
return values.map((value, i) => { | |
const data = {}; | |
data.index = i; | |
data.value = value; | |
data.rate = value / totalValue; |
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
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<title>d3を使って円から円を直線で結ぶサンプル</title> | |
</head> | |
<body> | |
<div id="container"></div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script> | |
<script> |
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
// ========================================================================= | |
// https://en.wikipedia.org/wiki/Fibonacci_number#List_of_Fibonacci_numbers | |
// ========================================================================= | |
// for ES2015 | |
{ | |
const fibonacci = Object.assign(function f(n){return +n!==parseInt(n)||!isFinite(n)?NaN:Math.abs(n)>1476?Math.sign(n)*Infinity:(n>=0?1:~n%2?-1:1)*(f[Math.abs(n)]||(f[Math.abs(n)-1]=f(Math.abs(n)-1))+f[Math.abs(n)-2])},{"-2":-1,"-1":1,0:0,1:1}); | |
const positiveIntegers = [...[...Array(21).keys()], 100, 999, 1476, 1477, 1478, 1479]; |
NewerOlder