-
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
307 changed files
with
5,204 additions
and
2,490 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
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,20 @@ | ||
import * as method from "./method"; | ||
|
||
declare global { | ||
interface Array<T> { | ||
all(fn?: (value: T, index: number, array: T[]) => boolean): boolean; | ||
} | ||
} | ||
|
||
/** | ||
* Returns `true` if the provided predicate function returns `true` for all elements in a collection, `false` otherwise | ||
* @memberof Array | ||
* @param {function} [fn=Boolean] | ||
* @returns {boolean} | ||
* @example | ||
* [4, 2, 3].all((x) => x > 1); // true | ||
* [1, 2, 3].all(); // true | ||
*/ | ||
Array.prototype.all = function(fn) { | ||
return method(this, fn); | ||
}; |
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 @@ | ||
const all = (arr: any[], fn: (value: any, index: number, array: any[]) => boolean = Boolean) => arr.every(fn); | ||
|
||
export = all; |
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,11 @@ | ||
import "./index"; | ||
|
||
describe("Array.prototype.all", () => { | ||
test("[4, 2, 3].all((x) => x > 1) returns true", () => { | ||
expect([4, 2, 3].all((x) => x > 1)).toBe(true); | ||
}); | ||
|
||
test("[1, 2, 3].all() returns true", () => { | ||
expect([1, 2, 3].all()).toBe(true); | ||
}); | ||
}); |
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,21 @@ | ||
import * as method from "./method"; | ||
|
||
declare global { | ||
interface Array<T> { | ||
any(fn?: (value: T, index: number, array: T[]) => boolean): boolean; | ||
} | ||
} | ||
|
||
/** | ||
* Returns `true` if the provided predicate function returns `true` for at least one element in a collection, | ||
* `false` otherwise | ||
* @memberof Array | ||
* @param {function} [fn=Boolean] | ||
* @returns {boolean} | ||
* @example | ||
* [0, 1, 2, 0].any((x) => x >= 2); // true | ||
* [0, 0, 1, 0].any(); // true | ||
*/ | ||
Array.prototype.any = function(fn) { | ||
return method(this, fn); | ||
}; |
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 @@ | ||
const method = (arr: any[], fn: (value: any, index: number, array: any[]) => boolean = Boolean) => arr.some(fn); | ||
|
||
export = method; |
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,11 @@ | ||
import "./index"; | ||
|
||
describe("Array.prototype.any", () => { | ||
test("[0, 1, 2, 0].any((x) => x >= 2) returns true", () => { | ||
expect([0, 1, 2, 0].any((x) => x >= 2)).toBe(true); | ||
}); | ||
|
||
test("[0, 0, 1, 0].any() returns true", () => { | ||
expect([0, 0, 1, 0].any()).toBe(true); | ||
}); | ||
}); |
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,9 @@ | ||
const method = (arr: any[], value: any) => { | ||
const array = arr.concat([value]); | ||
|
||
arr.length = 0; | ||
|
||
arr.push(...array); | ||
}; | ||
|
||
export = method; |
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,11 +1,13 @@ | ||
require('../../../es6/array/append') | ||
import "./index"; | ||
|
||
describe("Array.prototype.append", () => { | ||
test("myArray = [1, 2, 3] & myArray.append(0) results myArray to be [1, 2, 3, 0]", () => { | ||
expect((() => { | ||
let myArray = [1, 2, 3] | ||
myArray.append(0) | ||
return myArray | ||
})()).toEqual([1, 2, 3, 0]) | ||
}) | ||
}) | ||
const myArray = [1, 2, 3]; | ||
|
||
myArray.append(0); | ||
|
||
return myArray; | ||
})()).toEqual([1, 2, 3, 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,5 @@ | ||
import * as sum from "../sum/method"; | ||
|
||
const method = (arr: any[], key?: string) => sum(arr, key) / arr.length; | ||
|
||
export = method; |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
import "./index"; | ||
|
||
describe("Array.prototype.average", () => { | ||
test("[1, 2, 3].average() returns 2", () => { | ||
expect([1, 2, 3].average()).toBe(2); | ||
}); | ||
|
||
test("[{a: 1}, {a: 2}, {a: 3}].average(\"a\") returns 2", () => { | ||
expect([{ a: 1 }, { a: 2 }, { a: 3 }].average("a")).toBe(2); | ||
}); | ||
|
||
test("[{a: {b: 1}}, {a: {b: 2}}, {a: {b: 3}}].average(\"a.b\") returns 2", () => { | ||
expect([{ a: { b: 1 } }, { a: { b: 2 } }, { a: { b: 3 } }].average("a.b")).toBe(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
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 @@ | ||
const method = (arr: any[], size: number): any[][] => { | ||
return Array.from( | ||
{ | ||
length: Math.ceil(arr.length / size), | ||
}, | ||
(value: any, index: number) => arr.slice(index * size, index * size + size), | ||
); | ||
}; | ||
|
||
export = method; |
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,7 +1,7 @@ | ||
require('../../../es6/array/chunk') | ||
import "./index"; | ||
|
||
describe("Array.prototype.chunk", () => { | ||
test("[1, 2, 3, 4, 5].chunk(2) returns [[1,2],[3,4],[5]]", () => { | ||
expect([1,2,3,4,5].chunk(2)).toEqual([[1,2],[3,4],[5]]) | ||
}) | ||
}) | ||
expect([1, 2, 3, 4, 5].chunk(2)).toEqual([[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
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 @@ | ||
const method = (arr: any[]) => [...arr]; | ||
|
||
export = method; |
Oops, something went wrong.