Skip to content

Commit

Permalink
Run through prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
hiquest committed May 1, 2019
1 parent baf23aa commit e7efd28
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 75 deletions.
5 changes: 2 additions & 3 deletions exercises/easy/01_map.test.js
Expand Up @@ -10,11 +10,10 @@
*/

function map(arr, fn) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('maps an array', () =>
expect(map([1, 2, 3], x => x ** 2)).toEqual([1, 4, 9])
)
expect(map([1, 2, 3], x => x ** 2)).toEqual([1, 4, 9]))
5 changes: 2 additions & 3 deletions exercises/easy/02_filter.test.js
Expand Up @@ -8,11 +8,10 @@
*/

function filter(arr, fn) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('maps an array', () =>
expect(filter([-1, 0, 1, 2, 3], x => x > 0)).toEqual([1, 2, 3])
)
expect(filter([-1, 0, 1, 2, 3], x => x > 0)).toEqual([1, 2, 3]))
5 changes: 2 additions & 3 deletions exercises/easy/03_uniq.test.js
Expand Up @@ -6,11 +6,10 @@
*/

function uniq(arr) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('removes duplicates from an array', () =>
expect(uniq([1, 1, 2, 3, 3, 1])).toEqual([1, 2, 3])
)
expect(uniq([1, 1, 2, 3, 3, 1])).toEqual([1, 2, 3]))
17 changes: 8 additions & 9 deletions exercises/extra-hard/10_curry.test.js
Expand Up @@ -7,19 +7,18 @@
*/

function curry(fn, arity) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('curries a function', () =>
expect(curry((x, y) => x + y)(5)(10)).toEqual(15)
)
expect(curry((x, y) => x + y)(5)(10)).toEqual(15))

test('curries a function of many arguments', () => {
const sum = curry((a, b, c) => a + b + c)
expect(sum(1, 2, 3)).toEqual(6)
expect(sum(1)(2, 3)).toEqual(6)
expect(sum(1, 2)(3)).toEqual(6)
expect(sum(1)(2)(3)).toEqual(6)
})
const sum = curry((a, b, c) => a + b + c)
expect(sum(1, 2, 3)).toEqual(6)
expect(sum(1)(2, 3)).toEqual(6)
expect(sum(1, 2)(3)).toEqual(6)
expect(sum(1)(2)(3)).toEqual(6)
})
24 changes: 12 additions & 12 deletions exercises/extra-hard/11_debounce.test.js
Expand Up @@ -7,20 +7,20 @@
*/

function debounce(func, wait, immediate) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('debounce', done => {
const costlyFn = jest.fn()
const fn = debounce(costlyFn, 100)
fn()
fn()
fn()
expect(costlyFn).toHaveBeenCalledTimes(0)
setTimeout(() => {
expect(costlyFn).toHaveBeenCalledTimes(1)
done()
}, 200)
})
const costlyFn = jest.fn()
const fn = debounce(costlyFn, 100)
fn()
fn()
fn()
expect(costlyFn).toHaveBeenCalledTimes(0)
setTimeout(() => {
expect(costlyFn).toHaveBeenCalledTimes(1)
done()
}, 200)
})
16 changes: 8 additions & 8 deletions exercises/hard/07_sample.test.js
Expand Up @@ -6,16 +6,16 @@
*/

function sample(arr, n) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('returns a sample from an array', () => {
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for (i = 0; i < 10; i++) {
const out = sample(numbers, 3)
expect(out.length).toEqual(3)
expect(out.every(x => x >= 1 && x <= 9)).toEqual(true)
}
})
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for (i = 0; i < 10; i++) {
const out = sample(numbers, 3)
expect(out.length).toEqual(3)
expect(out.every(x => x >= 1 && x <= 9)).toEqual(true)
}
})
9 changes: 3 additions & 6 deletions exercises/hard/08_safeGet.test.js
Expand Up @@ -7,17 +7,14 @@
*/

function safeGet(obj, path) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

const obj = { a: { b: { c: 42 } } }

test('gets a value by path', () =>
expect(safeGet(obj, 'a.b.c')).toEqual(42)
)
test('gets a value by path', () => expect(safeGet(obj, 'a.b.c')).toEqual(42))

test('returns null for non-existing values', () =>
expect(safeGet(obj, 'a.b.c.d')).toEqual(null)
)
expect(safeGet(obj, 'a.b.c.d')).toEqual(null))
18 changes: 9 additions & 9 deletions exercises/hard/09_memoize.test.js
Expand Up @@ -7,17 +7,17 @@
*/

function memoize(fn) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('caches the value of a function', () => {
const costlyFn = jest.fn()
const fn = memoize(costlyFn)
fn(1)
fn(1)
fn(2)
fn(1)
expect(costlyFn).toHaveBeenCalledTimes(2)
})
const costlyFn = jest.fn()
const fn = memoize(costlyFn)
fn(1)
fn(1)
fn(2)
fn(1)
expect(costlyFn).toHaveBeenCalledTimes(2)
})
9 changes: 3 additions & 6 deletions exercises/medium/04_flatten.test.js
Expand Up @@ -5,15 +5,12 @@
*/

function flatten(arr) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('flattens an array', () =>
expect(flatten([[1, 2], 3])).toEqual([1, 2, 3])
)
test('flattens an array', () => expect(flatten([[1, 2], 3])).toEqual([1, 2, 3]))

test('deeply flattens an array', () =>
expect(flatten([[1], 2, [[3], 4]])).toEqual([1, 2, 3, 4])
)
expect(flatten([[1], 2, [[3], 4]])).toEqual([1, 2, 3, 4]))
5 changes: 2 additions & 3 deletions exercises/medium/05_reduce.test.js
Expand Up @@ -7,11 +7,10 @@
*/

function reduce(arr, fn, initial) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('reduces an array', () =>
expect(reduce([1, 2, 3, 4, 5], (a, b) => a + b, 0)).toEqual(15)
)
expect(reduce([1, 2, 3, 4, 5], (a, b) => a + b, 0)).toEqual(15))
27 changes: 14 additions & 13 deletions exercises/medium/06_break.test.js
Expand Up @@ -6,21 +6,22 @@
*/

function convert(arr) {
// TODO - IMPLEMENT ME
// TODO - IMPLEMENT ME
}

/* =========== DON'T CHANGE THE CODE AFTER THIS LINE =============== */

test('reduces an array', () =>
expect(convert([
{ name: 'John', hobbies: ['singing', 'walking', 'playing guitar'] },
{ name: 'Terry', hobbies: ['swimming', 'playing guitar'] },
{ name: 'Anna', hobbies: ['walking', 'swimming', 'playing guitar'] },
{ name: 'Paul', hobbies: ['swimming', 'singing'] }
])).toEqual([
{ hobby: 'singing', users: ['John', 'Paul'] },
{ hobby: 'walking', users: ['John', 'Anna'] },
{ hobby: 'playing guitar', users: ['John', 'Terry', 'Anna'] },
{ hobby: 'swimming', users: ['Terry', 'Anna', 'Paul'] }
])
)
expect(
convert([
{ name: 'John', hobbies: ['singing', 'walking', 'playing guitar'] },
{ name: 'Terry', hobbies: ['swimming', 'playing guitar'] },
{ name: 'Anna', hobbies: ['walking', 'swimming', 'playing guitar'] },
{ name: 'Paul', hobbies: ['swimming', 'singing'] },
]),
).toEqual([
{ hobby: 'singing', users: ['John', 'Paul'] },
{ hobby: 'walking', users: ['John', 'Anna'] },
{ hobby: 'playing guitar', users: ['John', 'Terry', 'Anna'] },
{ hobby: 'swimming', users: ['Terry', 'Anna', 'Paul'] },
]))

0 comments on commit e7efd28

Please sign in to comment.