-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84dfec9
commit fb5638a
Showing
15 changed files
with
348 additions
and
6 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
{ | ||
"clamp": "clamp", | ||
"divMod": "divMod", | ||
"isEven": "isEven", | ||
"isOdd": "isOdd", | ||
"mean": "mean", | ||
"median": "median", | ||
"mode": "mode", | ||
"percentage": "percentage", | ||
"percentageOf": "percentageOf" | ||
"percentageOf": "percentageOf", | ||
"prod": "prod", | ||
"sum": "sum" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import REPL from "../../components/REPL"; | ||
|
||
> Returns a tuple with `Quotient` and `Remainder`. | ||
## Syntax | ||
|
||
```ts | ||
import { divMod } from '@opentf/std'; | ||
|
||
divMod(a: number, b: number): [number, number] | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
divMod(4, 2) //=> [2, 0]); | ||
|
||
divMod(11, 4) //=> [2.75, 3]); | ||
|
||
divMod(1, 0) //=> [Infinity, NaN]); | ||
|
||
divMod(0, 1) //=> [0, 0]); | ||
|
||
divMod(-9, -2) //=> [4.5, -1]); | ||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { divMod } = require('@opentf/std'); | ||
divMod(4, 2); | ||
`} /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import REPL from "../../components/REPL"; | ||
|
||
> Checks if the given number is an `Even` number. | ||
## Syntax | ||
|
||
```ts | ||
import { isEven } from '@opentf/std'; | ||
|
||
isEven(n: number): boolean | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
isEven(0) //=> true | ||
|
||
isEven(1) //=> false | ||
|
||
isEven(2) //=> true | ||
|
||
isEven(-1) //=> false | ||
|
||
isEven(-2) //=> true | ||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { isEven } = require('@opentf/std'); | ||
isEven(42); | ||
`} /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import REPL from "../../components/REPL"; | ||
|
||
> Checks if the given number is a `Odd` number. | ||
## Syntax | ||
|
||
```ts | ||
import { isOdd } from '@opentf/std'; | ||
|
||
isOdd(n: number): boolean | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
isOdd(0) //=> false | ||
|
||
isOdd(1) //=> true | ||
|
||
isOdd(2) //=> false | ||
|
||
isOdd(-1) //=> true | ||
|
||
isOdd(-2) //=> false | ||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { isOdd } = require('@opentf/std'); | ||
isOdd(9); | ||
`} /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Callout } from "nextra/components"; | ||
import REPL from "../../components/REPL"; | ||
|
||
> Calculates the `mean` value of the given array. | ||
<Callout type="info"> | ||
Mean: The "average" number; found by adding all data points and dividing by the number of data points. | ||
<div style={{textAlign: 'right'}}> | ||
\- [Khan Academy](https://www.khanacademy.org/math/statistics-probability/summarizing-quantitative-data/mean-median-basics/a/mean-median-and-mode-review) | ||
</div> | ||
</Callout> | ||
|
||
## Syntax | ||
|
||
```ts | ||
import { mean } from '@opentf/std'; | ||
|
||
mean( | ||
arr: number[] = [], | ||
cb?: (v: number, index: number) => number | ||
): number | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
mean([]) //=> NaN | ||
|
||
mean([1]) //=> 1 | ||
|
||
mean([4, 1, 7]) //=> 4 | ||
|
||
mean([4, 2, 8]) //=> 4.67 | ||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { mean } = require('@opentf/std'); | ||
mean([4, 2, 8]); | ||
`} /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Callout } from "nextra/components"; | ||
import REPL from "../../components/REPL"; | ||
|
||
> Calculates the `median` value of the given array. | ||
<Callout type="info"> | ||
Median: The middle number; found by ordering all data points and picking out the one in the middle (or if there are two middle numbers, taking the mean of those two numbers). | ||
<div style={{textAlign: 'right'}}> | ||
\- [Khan Academy](https://www.khanacademy.org/math/statistics-probability/summarizing-quantitative-data/mean-median-basics/a/mean-median-and-mode-review) | ||
</div> | ||
</Callout> | ||
|
||
## Syntax | ||
|
||
```ts | ||
import { median } from '@opentf/std'; | ||
|
||
median( | ||
arr: number[] = [], | ||
cb?: (val: number, index: number) => number | ||
): number | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
median([]) //=> NaN | ||
|
||
median([1]) //=> 1 | ||
|
||
median([4, 1, 7]) //=> 1 | ||
|
||
median([4, 2, 8]) //=> 2 | ||
|
||
median([1, 4, 2, 5, 0]) //=> 2 | ||
|
||
median([10, 20, 40, 50]) //=> 30 | ||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { median } = require('@opentf/std'); | ||
median([10, 20, 40, 50]); | ||
`} /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Callout } from "nextra/components"; | ||
import REPL from "../../components/REPL"; | ||
|
||
> Calculates the `mode` value of the given array. | ||
<Callout type="info"> | ||
Mode: The most frequent number—that is, the number that occurs the highest number of times. | ||
<div style={{textAlign: 'right'}}> | ||
\- [Khan Academy](https://www.khanacademy.org/math/statistics-probability/summarizing-quantitative-data/mean-median-basics/a/mean-median-and-mode-review) | ||
</div> | ||
</Callout> | ||
|
||
## Syntax | ||
|
||
```ts | ||
import { mode } from '@opentf/std'; | ||
|
||
mode<T>( | ||
arr: T[] = [], | ||
cb?: (val: T, index: number) => number | ||
): number[] | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
mode([1]) //=> [] | ||
|
||
mode([1, 2, 3, 4, 5]) //=> [] | ||
|
||
mode([4, 2]) //=> [] | ||
|
||
mode([4, 2, 3, 2, 2]) //=> [2] | ||
|
||
mode([0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 4]) //=> [1, 2] | ||
|
||
mode([{ n: 1 }, { n: 2 }, { n: 3 }, { n: 2 }], ({ n }) => n) //=> [2] | ||
|
||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { mode } = require('@opentf/std'); | ||
mode([0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 4]); | ||
`} /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import REPL from "../../components/REPL"; | ||
|
||
> Calculates the `product` of values in the given array. | ||
## Syntax | ||
|
||
```ts | ||
import { prod } from '@opentf/std'; | ||
|
||
prod( | ||
arr: number[] = [], | ||
cb?: (val: number, index: number) => number | ||
): number | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
prod() //=> 1 | ||
|
||
prod([]) //=> 1 | ||
|
||
prod([1]) //=> 1 | ||
|
||
prod([1, -1]) //=> -1 | ||
|
||
prod([-1, -2]) //=> 2 | ||
|
||
prod([1, 2, 3, 4, 5]) //=> 120 | ||
|
||
const objects = [{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }]; | ||
prod(objects, (v) => v.n) //=> 384 | ||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { prod } = require('@opentf/std'); | ||
prod([1, 2, 3, 4, 5]); | ||
`} /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import REPL from "../../components/REPL"; | ||
|
||
> Calculates the `sum` of values in the given array. | ||
## Syntax | ||
|
||
```ts | ||
import { sum } from '@opentf/std'; | ||
|
||
sum( | ||
arr: number[] = [], | ||
cb?: (val: number, index: number) => number | ||
): number | ||
``` | ||
|
||
## Examples | ||
|
||
```ts | ||
sum() //=> 0 | ||
|
||
sum([]) //=> 0 | ||
|
||
sum([1]) //=> 1 | ||
|
||
sum([1, -1]) //=> 0 | ||
|
||
sum([-1, -2]) //=> -3 | ||
|
||
sum([1, 2, 3, 4, 5]) //=> 15 | ||
|
||
sum([1.2, Math.PI]) //=> 4.34 | ||
|
||
sum([1, 2, 3, 4, 5.4], Math.round) //=> 15 | ||
|
||
const objects = [{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }]; | ||
sum(objects, (v) => v.n) //=> 20 | ||
|
||
sum(objects, (v, i) => v.n * i) //=> 36 | ||
|
||
sum([Infinity, Infinity]) //=> Infinity | ||
|
||
``` | ||
|
||
## Try | ||
|
||
<REPL code={`const { sum } = require('@opentf/std'); | ||
sum([1, 2, 3, 4, 5]); | ||
`} /> |
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
Oops, something went wrong.