diff --git a/scripts/build.js b/scripts/build.js index dc270b4cf..8c8d964e1 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -43,7 +43,7 @@ These snippets, while useful and interesting, didn\'t quite make it into the rep ## Table of Contents -` +`; for(const snippet of Object.entries(snippets)) output += `* [\`${snippet[0].slice(0,-3)}\`](#${snippet[0].toLowerCase().slice(0,-3)})\n`; output += '\n---\n'; diff --git a/snippets_archive/binarySearch.md b/snippets_archive/binarySearch.md index 3645954cb..ad5b2c758 100644 --- a/snippets_archive/binarySearch.md +++ b/snippets_archive/binarySearch.md @@ -1,11 +1,11 @@ ### binarySearch -Use recursion. Similar to `Array.indexOf()` that finds the index of a value within an array. +Use recursion. Similar to `Array.indexOf()` that finds the index of a value within an array. The difference being this operation only works with sorted arrays which offers a major performance boost due to it's logarithmic nature when compared to a linear search or `Array.indexOf()`. -Search a sorted array by repeatedly dividing the search interval in half. -Begin with an interval covering the whole array. -If the value of the search is less than the item in the middle of the interval, recurse into the lower half. Otherwise recurse into the upper half. +Search a sorted array by repeatedly dividing the search interval in half. +Begin with an interval covering the whole array. +If the value of the search is less than the item in the middle of the interval, recurse into the lower half. Otherwise recurse into the upper half. Repeatedly recurse until the value is found which is the mid or you've recursed to a point that is greater than the length which means the value doesn't exist and return `-1`. ```js @@ -15,8 +15,8 @@ const binarySearch = (arr, val, start = 0, end = arr.length - 1) => { if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1); if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end); return mid; -} -``` +}; +``` ```js binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6); // 2 diff --git a/test/README/README.js b/test/README/README.js deleted file mode 100644 index 7286e4ffb..000000000 --- a/test/README/README.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = README = e = arr => { -const dt = new Date(parseInt(arr.toString().substr(6))); -return `${dt.getDate()}/${dt.getMonth() + 1}/${dt.getFullYear()}`; -}; \ No newline at end of file diff --git a/test/README/README.test.js b/test/README/README.test.js deleted file mode 100644 index 7ae30976a..000000000 --- a/test/README/README.test.js +++ /dev/null @@ -1,13 +0,0 @@ -const test = require('tape'); -const README = require('./README.js'); - -test('Testing README', (t) => { - //For more information on all the methods supported by tape - //Please go to https://github.com/substack/tape - t.true(typeof README === 'function', 'README is a Function'); - //t.deepEqual(README(args..), 'Expected'); - //t.equal(README(args..), 'Expected'); - //t.false(README(args..), 'Expected'); - //t.throws(README(args..), 'Expected'); - t.end(); -}); \ No newline at end of file diff --git a/test/ary/ary.test.js b/test/ary/ary.test.js index 065b18a96..f73c1c40f 100644 --- a/test/ary/ary.test.js +++ b/test/ary/ary.test.js @@ -6,7 +6,7 @@ test('Testing ary', (t) => { //Please go to https://github.com/substack/tape t.true(typeof ary === 'function', 'ary is a Function'); const firstTwoMax = ary(Math.max, 2); - t.deepEquals([[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)), [6, 8, 10], 'Discards arguments with index >=n') + t.deepEquals([[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)), [6, 8, 10], 'Discards arguments with index >=n'); //t.deepEqual(ary(args..), 'Expected'); //t.equal(ary(args..), 'Expected'); //t.false(ary(args..), 'Expected'); diff --git a/test/attempt/attempt.test.js b/test/attempt/attempt.test.js index 13ae65686..557d7af3b 100644 --- a/test/attempt/attempt.test.js +++ b/test/attempt/attempt.test.js @@ -6,7 +6,7 @@ test('Testing attempt', (t) => { //Please go to https://github.com/substack/tape t.true(typeof attempt === 'function', 'attempt is a Function'); t.equals(attempt(() => 0), 0, 'Returns a value'); - t.true(attempt(() => {throw new Error()}) instanceof Error, 'Returns an error'); + t.true(attempt(() => {throw new Error();}) instanceof Error, 'Returns an error'); //t.deepEqual(attempt(args..), 'Expected'); //t.equal(attempt(args..), 'Expected'); //t.false(attempt(args..), 'Expected'); diff --git a/test/binarySearch/binarySearch.js b/test/binarySearch/binarySearch.js index 38cedecce..6813e1936 100644 --- a/test/binarySearch/binarySearch.js +++ b/test/binarySearch/binarySearch.js @@ -4,5 +4,5 @@ const mid = Math.floor((start + end) / 2); if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1); if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end); return mid; -} -module.exports = binarySearch; \ No newline at end of file +}; +module.exports = binarySearch; diff --git a/test/bindAll/bindAll.test.js b/test/bindAll/bindAll.test.js index 90c9e23a8..ccf1f00a3 100644 --- a/test/bindAll/bindAll.test.js +++ b/test/bindAll/bindAll.test.js @@ -10,7 +10,7 @@ test('Testing bindAll', (t) => { 'click': function() { return 'clicked ' + this.label; } - } + }; bindAll(view, 'click'); t.equal(view.click(), 'clicked docs', 'Binds to an object context') //t.deepEqual(bindAll(args..), 'Expected'); diff --git a/test/equals/equals.test.js b/test/equals/equals.test.js index 3c4caf3aa..fd7f0e8f4 100644 --- a/test/equals/equals.test.js +++ b/test/equals/equals.test.js @@ -9,7 +9,7 @@ test('Testing equals', (t) => { t.true(equals([1, 2, 3], [1, 2, 3]), '[1,2,3] is equal to [1,2,3]'); t.false(equals({ a: [2, 3], b: [4] }, { a: [2, 3], b: [6] }), '{ a: [2, 3], b: [4] } is not equal to { a: [2, 3], b: [6] }'); t.false(equals([1, 2, 3], [1, 2, 4]), '[1,2,3] is not equal to [1,2,4]'); - t.true(equals([1, 2, 3], { 0: 1, 1: 2, 2: 3 }), '[1, 2, 3] should be equal to { 0: 1, 1: 2, 2: 3 }) - type is different, but their enumerable properties match.') + t.true(equals([1, 2, 3], { 0: 1, 1: 2, 2: 3 }), '[1, 2, 3] should be equal to { 0: 1, 1: 2, 2: 3 }) - type is different, but their enumerable properties match.'); //t.deepEqual(equals(args..), 'Expected'); //t.equal(equals(args..), 'Expected'); //t.false(equals(args..), 'Expected'); diff --git a/test/isArray/isArray.js b/test/isArray/isArray.js index 267942368..87262d629 100644 --- a/test/isArray/isArray.js +++ b/test/isArray/isArray.js @@ -1,2 +1,2 @@ const isArray = val => Array.isArray(val); - module.exports = isArray \ No newline at end of file + module.exports = isArray; diff --git a/test/isMap/isMap.js b/test/isMap/isMap.js index 9c62ac7ce..1de74fe8d 100644 --- a/test/isMap/isMap.js +++ b/test/isMap/isMap.js @@ -1,2 +1,2 @@ const isMap = val => val instanceof Map; - module.exports = isMap \ No newline at end of file + module.exports = isMap; diff --git a/test/isSorted/isSorted.test.js b/test/isSorted/isSorted.test.js index 9d80c6c8e..108e29e6d 100644 --- a/test/isSorted/isSorted.test.js +++ b/test/isSorted/isSorted.test.js @@ -8,8 +8,8 @@ test('Testing isSorted', (t) => { //t.deepEqual(isSorted(args..), 'Expected'); t.equal(isSorted([0, 1, 2, 2]), 1, 'Array is sorted in ascending order'); t.equal(isSorted([4, 3, 2]), -1, 'Array is sorted in descending order'); - t.equal(isSorted([4, 3, 5]), 0, 'Array is not sorted, direction changed in array') + t.equal(isSorted([4, 3, 5]), 0, 'Array is not sorted, direction changed in array'); //t.false(isSorted(args..), 'Expected'); //t.throws(isSorted(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/isTypedArray/isTypedArray.js b/test/isTypedArray/isTypedArray.js index 007bb179c..221deb7da 100644 --- a/test/isTypedArray/isTypedArray.js +++ b/test/isTypedArray/isTypedArray.js @@ -1,2 +1,2 @@ const isTypedArray = val => val instanceof TypedArray; - module.exports = isTypedArray \ No newline at end of file + module.exports = isTypedArray; diff --git a/test/isWeakMap/isWeakMap.js b/test/isWeakMap/isWeakMap.js index 7d3936490..ce857ea77 100644 --- a/test/isWeakMap/isWeakMap.js +++ b/test/isWeakMap/isWeakMap.js @@ -1,2 +1,2 @@ const isWeakMap = val => val instanceof WeakMap; - module.exports = isWeakMap \ No newline at end of file + module.exports = isWeakMap; diff --git a/test/isWeakSet/isWeakSet.js b/test/isWeakSet/isWeakSet.js index 66237e12e..bea588905 100644 --- a/test/isWeakSet/isWeakSet.js +++ b/test/isWeakSet/isWeakSet.js @@ -1,2 +1,2 @@ const isWeakSet = val => val instanceof WeakSet; - module.exports = isWeakSet \ No newline at end of file + module.exports = isWeakSet; diff --git a/test/quickSort/quickSort.test.js b/test/quickSort/quickSort.test.js index 067b62ce5..86ef548a4 100644 --- a/test/quickSort/quickSort.test.js +++ b/test/quickSort/quickSort.test.js @@ -17,6 +17,6 @@ test('Testing quickSort', (t) => { quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]); let end = new Date().getTime(); t.true((end - start) < 2000, 'quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run'); - + t.end(); -}); \ No newline at end of file +}); diff --git a/test/take/take.test.js b/test/take/take.test.js index 2d2aed44c..030024725 100644 --- a/test/take/take.test.js +++ b/test/take/take.test.js @@ -5,11 +5,11 @@ test('Testing take', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof take === 'function', 'take is a Function'); - t.deepEqual(take([1, 2, 3], 5), [1, 2, 3], "Returns an array with n elements removed from the beginning.") - t.deepEqual(take([1, 2, 3], 0), [], "Returns an array with n elements removed from the beginning.") + t.deepEqual(take([1, 2, 3], 5), [1, 2, 3], "Returns an array with n elements removed from the beginning."); + t.deepEqual(take([1, 2, 3], 0), [], "Returns an array with n elements removed from the beginning."); //t.deepEqual(take(args..), 'Expected'); //t.equal(take(args..), 'Expected'); //t.false(take(args..), 'Expected'); //t.throws(take(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/testlog b/test/testlog index 43b1a79e5..93328ad4a 100644 --- a/test/testlog +++ b/test/testlog @@ -1,4 +1,4 @@ -Test log for: Sun Feb 04 2018 17:47:43 GMT+0200 (GTB Standard Time) +Test log for: Sun Feb 04 2018 17:54:05 GMT+0200 (GTB Standard Time) > 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code > tape test/**/*.test.js | tap-spec @@ -1177,10 +1177,6 @@ Test log for: Sun Feb 04 2018 17:47:43 GMT+0200 (GTB Standard Time) √ readFileLines is a Function - Testing README - - √ README is a Function - Testing rearg √ rearg is a Function @@ -1709,8 +1705,8 @@ Test log for: Sun Feb 04 2018 17:47:43 GMT+0200 (GTB Standard Time) √ Works with multiple promises - total: 813 - passing: 813 - duration: 2.4s + total: 812 + passing: 812 + duration: 2.5s diff --git a/test/uniqueElements/uniqueElements.test.js b/test/uniqueElements/uniqueElements.test.js index 137f791dc..2dd158e08 100644 --- a/test/uniqueElements/uniqueElements.test.js +++ b/test/uniqueElements/uniqueElements.test.js @@ -18,7 +18,7 @@ test('Testing uniqueElements', (t) => { t.throws(() => uniqueElements(false), 'uniqueElements(false) throws an error'); let start = new Date().getTime(); - uniqueElements([true, 0, 1, false, false, undefined, null, '']) + uniqueElements([true, 0, 1, false, false, undefined, null, '']); let end = new Date().getTime(); t.true((end - start) < 2000, 'uniqueElements([true, 0, 1, false, false, undefined, null]) takes less than 2s to run');