-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
8 changed files
with
75 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { formatLatin } from "./formatLatin"; | ||
|
||
const accentString = | ||
"áéíóúüñ¿¡àâèêëîïôûàãàãçàèéìòóùäöüßáéíóúáéíóúąćęłńóśźżáčďéěíňóřšťúůýžćčđšžáéíóúüαβγδεζηθικλμνξοπρστυφχψωçğıİöşüابتثجحخدذرزسشصضطظعغ"; | ||
const latinString = "aeiou"; | ||
|
||
describe("formatLatin", () => { | ||
test("should return a-z", () => { | ||
expect(formatLatin(accentString)).toBe(latinString); | ||
}); | ||
}); |
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,4 @@ | ||
export const formatLatin = (text: string): string => { | ||
let normalized = text.normalize("NFKD"); | ||
return normalized; | ||
}; |
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,10 @@ | ||
import { max } from "./max"; | ||
import { min } from "./min"; | ||
import { normaliseNumber } from "./normaliseNumber"; | ||
|
||
export const normaliseArray = (values: number[]) => { | ||
const minValue = min(values); | ||
const maxValue = max(values); | ||
|
||
return values.map((value) => normaliseNumber(value, minValue, maxValue)); | ||
}; |
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,5 @@ | ||
export const normaliseNumber = ( | ||
value: number, | ||
minValue: number, | ||
maxValue: number | ||
) => (value - minValue) / (maxValue - minValue); |
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
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,35 +1,43 @@ | ||
export const randomInt = (min: number = -100, max: number = 100): number => { | ||
export const randomInt = ({ | ||
min = -100, | ||
max = 100, | ||
}: { | ||
min?: number; | ||
max?: number; | ||
} = {}): number => { | ||
min = Math.ceil(min); // in case is a float | ||
max = Math.floor(max); // in case is a float | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
}; | ||
|
||
export const randomPositiveInt = (max: number = 100): number => | ||
randomInt(1, max); | ||
|
||
export const randomNegativeInt = (min: number = -100): number => | ||
randomInt(min, -1); | ||
|
||
export const randomMaxSafeInt = () => | ||
randomInt(-Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER); | ||
|
||
export const randomMaxInt = () => | ||
randomInt(-Number.MAX_VALUE, Number.MAX_VALUE); | ||
|
||
export const randomPercentage = ({ | ||
min, | ||
max, | ||
export const randomPositiveInt = ({ | ||
min = 1, | ||
max = 100, | ||
}: { | ||
min?: number; | ||
max?: number; | ||
} = {}) => randomInt(min ?? -100, max ?? 100); | ||
} = {}): number => | ||
randomInt({ | ||
min, | ||
max, | ||
}); | ||
|
||
export const randomPositivePercentage = ({ | ||
min, | ||
max, | ||
export const randomNegativeInt = ({ | ||
min = -100, | ||
max = -1, | ||
}: { | ||
min?: number; | ||
max?: number; | ||
} = {}) => randomInt(min ?? 1, max ?? 100); | ||
} = {}): number => | ||
randomInt({ | ||
min, | ||
max, | ||
}); | ||
|
||
export const randomMaxSafeInt = () => | ||
randomInt({ min: -Number.MAX_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER }); | ||
|
||
export const randomMaxInt = () => | ||
randomInt({ min: -Number.MAX_VALUE, max: Number.MAX_VALUE }); | ||
|
||
export const randomFormattedPercentage = () => randomPercentage() + "%"; | ||
export const randomFormattedPercentage = () => randomInt() + "%"; |