mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
839 B
34 lines
839 B
4 years ago
|
Array.prototype.forEach = undefined
|
||
|
// /*/ // ⚡
|
||
|
export const tests = []
|
||
|
const t = (f) => tests.push(f)
|
||
|
|
||
|
export const setup = () => {
|
||
|
const arr = [1, 2, 3, 4, 5, Math.random(), 7, 10, -10, 20, -95]
|
||
|
Object.getPrototypeOf([]).proto = ' [avoid for..in] '
|
||
|
return { arr }
|
||
|
}
|
||
|
|
||
|
// callback is call with the item value
|
||
|
t(({ eq, ctx }) => {
|
||
|
const result = []
|
||
|
forEach(ctx.arr, (value) => result.push(value))
|
||
|
return eq(result, ctx.arr)
|
||
|
})
|
||
|
|
||
|
// callback second parameter is the index
|
||
|
t(({ eq, ctx }) => {
|
||
|
const result = []
|
||
|
forEach(ctx.arr, (_, index) => result.push(index))
|
||
|
return eq(result, [...ctx.arr.keys()])
|
||
|
})
|
||
|
|
||
|
// callback third parameter is the array
|
||
|
t(({ eq, ctx }) => {
|
||
|
const result = []
|
||
|
forEach(ctx.arr, (_, __, arr) => result.push(arr))
|
||
|
return eq(result, Array(ctx.arr.length).fill(ctx.arr))
|
||
|
})
|
||
|
|
||
|
Object.freeze(tests)
|