This is named after Ramda's aperture function https://ramdajs.com/docs/#aperture.
const aperture = (n: number) =>
<T>(xs: T[]): T[][] =>
n < 1 || n > xs.length
? []
: Array.from({ length: xs.length - n + 1 }, (_, i) => xs.slice(i, i + n));This is named after Ramda's aperture function https://ramdajs.com/docs/#aperture.
const aperture = (n: number) =>
<T>(xs: T[]): T[][] =>
n < 1 || n > xs.length
? []
: Array.from({ length: xs.length - n + 1 }, (_, i) => xs.slice(i, i + n));| [ | |
| { | |
| "name": "bug", | |
| "color": "#A8B820", | |
| "halfEffectiveAgainst": [ | |
| "fairy", | |
| "fighting", | |
| "fire", | |
| "flying", | |
| "ghost", |
| const swap = <T>(t: T[], i: number, j: number) => { | |
| [t[i], t[j]] = [t[j], t[i]]; | |
| }; | |
| export const shuffle = <T>(t: T[]) => { | |
| for (let i = t.length - 1; i > 0; i -= 1) { | |
| const j = Math.floor(Math.random() * (i + 1)); | |
| swap(t, i, j); | |
| } | |
| }; |
const normalize = (min: number) => (max: number) => (x: number) => (x - min) / (max - min);
// usage
const min = 25;
const max = 100;
const n = normalize(min)(max);
const ns = [32, 62.5, 90].map(n);This gist isn't mathematically rigorous so don't expect it to be as formal as something you'd find in academia.
This problem arises in various math and computer science topics where your input range needs to be transformed to fit into a different range. For example, let's say you had frequency data of a song at a particular moment in time. Each sample is a value that ranges from 0 to 255. In interval notation, it would be written as [0, 255]. The square brackets denote that the endpoints are inclusive - in other words, 0 and 255 are acceptable. We want to take a sample in this range and map it to a different range. Let's say our output range is [-1, 1]. The [-1, 1] range actually pops up a lot in various fields such as graphics programming or trigonometry. For example the range for the sine and cosine functions is [-1, 1].
So we want to take the range [0, 255] and map it to the range [-1, 1]. Of course, we'd want the mapping t
I appreciate anyone that decides to support the stream but some people don't want their presence to be broadcasted.
I usually just find a playlist or collection of video game music or an OST to put on in the background.
type Point = {
x: number;
y: number;
};
const interpolate = (center: Point) => (amount: number) => (pt: Point) => {
return (n: number) => {
const angle = n * amount;
const c = Math.cos(angle);sveltekit uses what's called server-only modules where code located under $lib/server/ can only be accessed on the server. this is where i'd put all the db and bot functionality.
for example
$lib/server/db could contain an index.ts file that sets up the db and exports functions like getUsers
const db = setUpDB(DB_CONNECTION_STRING, DB_PASSWORD); // it's been a while since i've done this