From 536373e77bf5bd75a97099a527ba41ff844da8a7 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Tue, 6 Mar 2018 20:32:31 +0000 Subject: [PATCH] Travis build: 1782 [cron] --- .../recordAnimationFrames.js | 21 +++++++++++++++++++ .../recordAnimationFrames.test.js | 13 ++++++++++++ test/testlog | 12 +++++++---- test/zipWith/zipWith.js | 15 ++++++------- 4 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 test/recordAnimationFrames/recordAnimationFrames.js create mode 100644 test/recordAnimationFrames/recordAnimationFrames.test.js diff --git a/test/recordAnimationFrames/recordAnimationFrames.js b/test/recordAnimationFrames/recordAnimationFrames.js new file mode 100644 index 000000000..7e7ca9004 --- /dev/null +++ b/test/recordAnimationFrames/recordAnimationFrames.js @@ -0,0 +1,21 @@ +const recordAnimationFrames = (callback, autoStart = true) => { +let running = true, +raf; +const stop = () => { +running = false; +cancelAnimationFrame(raf); +}; +const start = () => { +running = true; +run(); +}; +const run = () => { +raf = requestAnimationFrame(() => { +callback(); +if (running) run(); +}); +}; +if (autoStart) start(); +return { start, stop }; +}; +module.exports = recordAnimationFrames; \ No newline at end of file diff --git a/test/recordAnimationFrames/recordAnimationFrames.test.js b/test/recordAnimationFrames/recordAnimationFrames.test.js new file mode 100644 index 000000000..2d366d62a --- /dev/null +++ b/test/recordAnimationFrames/recordAnimationFrames.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const recordAnimationFrames = require('./recordAnimationFrames.js'); + +test('Testing recordAnimationFrames', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof recordAnimationFrames === 'function', 'recordAnimationFrames is a Function'); + //t.deepEqual(recordAnimationFrames(args..), 'Expected'); + //t.equal(recordAnimationFrames(args..), 'Expected'); + //t.false(recordAnimationFrames(args..), 'Expected'); + //t.throws(recordAnimationFrames(args..), 'Expected'); + t.end(); +}); \ No newline at end of file diff --git a/test/testlog b/test/testlog index 2dd26f00d..2a246494d 100644 --- a/test/testlog +++ b/test/testlog @@ -1,4 +1,4 @@ -Test log for: Mon Mar 05 2018 20:32:06 GMT+0000 (UTC) +Test log for: Tue Mar 06 2018 20:32:25 GMT+0000 (UTC) > 30-seconds-of-code@0.0.2 test /home/travis/build/Chalarangelo/30-seconds-of-code > tape test/**/*.test.js | tap-spec @@ -1398,6 +1398,10 @@ Test log for: Mon Mar 05 2018 20:32:06 GMT+0000 (UTC) ✔ rearg is a Function ✔ Reorders arguments in invoked function + Testing recordAnimationFrames + + ✔ recordAnimationFrames is a Function + Testing redirect ✔ redirect is a Function @@ -1972,10 +1976,10 @@ Test log for: Mon Mar 05 2018 20:32:06 GMT+0000 (UTC) ✖ length of string is 8 - total: 988 - passing: 986 + total: 989 + passing: 987 failing: 2 - duration: 2.6s + duration: 2.4s undefined \ No newline at end of file diff --git a/test/zipWith/zipWith.js b/test/zipWith/zipWith.js index a1b2f338f..ca6af080c 100644 --- a/test/zipWith/zipWith.js +++ b/test/zipWith/zipWith.js @@ -1,11 +1,8 @@ -const zipWith = (...arrays) => { -const length = arrays.length; -let fn = length > 1 ? arrays[length - 1] : undefined; -fn = typeof fn == 'function' ? (arrays.pop(), fn) : undefined; -const maxLength = Math.max(...arrays.map(x => x.length)); -const result = Array.from({ length: maxLength }).map((_, i) => { -return Array.from({ length: arrays.length }, (_, k) => arrays[k][i]); -}); -return fn ? result.map(arr => fn(...arr)) : result; +const zipWith = (...array) => { +const fn = typeof array[array.length - 1] === 'function' ? array.pop() : undefined; +return Array.from( +{ length: Math.max(...array.map(a => a.length)) }, +(_, i) => (fn ? fn(...array.map(a => a[i])) : array.map(a => a[i])) +); }; module.exports = zipWith; \ No newline at end of file