-
-
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
13 changed files
with
97 additions
and
2 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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# deverything | ||
|
||
## 0.27.0 | ||
|
||
### Minor Changes | ||
|
||
- add math | ||
|
||
## 0.26.0 | ||
|
||
### Minor Changes | ||
|
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,5 +1,6 @@ | ||
export * from "./checks"; | ||
export * from "./helpers"; | ||
export * from "./math"; | ||
export * from "./random"; | ||
export * from "./types"; | ||
export * from "./validators"; |
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,13 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { average } from "./average"; | ||
|
||
describe("average", () => { | ||
test("no arg", async () => { | ||
expect(average([])).toBe(NaN); | ||
}); | ||
|
||
test("args", async () => { | ||
expect(average([1, 2])).toBe(1.5); | ||
expect(average([1, 2, 3, 4])).toBe(2.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,10 @@ | ||
/** | ||
* Calculates the average of a list of numbers. | ||
* @example | ||
* average([1, 2, 3, 4, 5]); // 3 | ||
* average(1, 2, 3, 4, 5); // 3 | ||
*/ | ||
export const average = (numbers: number[]): number => { | ||
const sum = numbers.reduce((total, num) => total + num, 0); | ||
return sum / numbers.length; | ||
}; |
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 * from "./average"; | ||
export * from "./max"; | ||
export * from "./min"; | ||
export * from "./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,4 @@ | ||
export const max = (values: number[]): number => { | ||
const maxValue = Math.max(...values); | ||
return 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,4 @@ | ||
export const min = (values: number[]): number => { | ||
const minValue = Math.min(...values); | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { sum, sumBy } from "./sum"; | ||
|
||
describe("sum", () => { | ||
test("simple", async () => { | ||
expect(sum([1, 2])).toBe(3); | ||
}); | ||
}); | ||
|
||
describe("sumBy", () => { | ||
test("simple", async () => { | ||
expect( | ||
sumBy([{ a: 1 }, { a: 2 }], (item) => { | ||
return item.a; | ||
}) | ||
).toBe(3); | ||
}); | ||
test("string", async () => { | ||
expect(sumBy([{ a: 1 }, { a: 2 }], "a")).toBe(3); | ||
}); | ||
test("complex", async () => { | ||
expect( | ||
sumBy([{ a: 1 }, { b: { a: 2 } }], (item) => { | ||
return item.a || item.b?.a; | ||
}) | ||
).toBe(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { PropertyAccessor, getProp } from "../_internals/getProp"; | ||
import { PlainObject } from "../types"; | ||
|
||
export const sum = (numbers: number[]) => { | ||
return numbers.reduce((total, num) => total + num, 0); | ||
}; | ||
|
||
export const sumBy = <T extends PlainObject>( | ||
items: T[], | ||
prop: PropertyAccessor<T> | ||
) => { | ||
return items.reduce((total, item) => total + getProp<T>(item, prop), 0); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const isLastIndex = (index: number, array: any[]) => { | ||
return index === array.length - 1; | ||
}; |