about summary refs log tree commit diff stats
path: root/js/b
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-08-20 11:33:58 -0400
committerelioat <elioat@tilde.institute>2024-08-20 11:33:58 -0400
commitc27d24ab1109b94720deb03dea68d1779e7f807d (patch)
treec45bf81f9ecea970a8943b90ce98880ec13e7924 /js/b
parente2ff70a282ab2e33d4aaf8c12ca9e5a2cfe4fd91 (diff)
downloadtour-c27d24ab1109b94720deb03dea68d1779e7f807d.tar.gz
*
Diffstat (limited to 'js/b')
-rw-r--r--js/b/b.js38
-rw-r--r--js/b/b.min.js4
-rw-r--r--js/b/tests.js39
3 files changed, 40 insertions, 41 deletions
diff --git a/js/b/b.js b/js/b/b.js
index 5462e93..ee33eef 100644
--- a/js/b/b.js
+++ b/js/b/b.js
@@ -119,40 +119,4 @@ const b = {
   },
 };
 
-// Tests! 
-// pipe
-const addOne = (x) => x + 1;
-const double = (x) => x * 2;
-console.assert(b.pipe(addOne, double)(3) === 8, 'Test for pipe failed');
-
-// compose
-console.assert(b.compose(double, addOne)(3) === 8, 'Test for compose failed');
-
-// identity
-console.assert(b.identity(5) === 5, 'Test for identity failed');
-
-// curry
-const add = (x, y) => x + y;
-const curriedAdd = b.curry(add);
-console.assert(curriedAdd(3)(4) === 7, 'Test for curry failed');
-
-// match
-const matchDigits = b.match()(/\d+/g);
-console.assert(JSON.stringify(matchDigits('a1b2c3')) === JSON.stringify(['1', '2', '3']), 'Test for match failed');
-
-// replace
-const censor = b.replace()(/badword/g, '****');
-console.assert(censor('This is a badword in a sentence.') === 'This is a **** in a sentence.', 'Test for replace failed');
-
-// filter
-const isEven = (x) => x % 2 === 0;
-const filterEvens = b.filter()(isEven);
-console.assert(JSON.stringify(filterEvens([1, 2, 3, 4])) === JSON.stringify([2, 4]), 'Test for filter failed');
-
-// map
-const mapDoubles = b.map()(double);
-console.assert(JSON.stringify(mapDoubles([1, 2, 3])) === JSON.stringify([2, 4, 6]), 'Test for map failed');
-
-// deepMap
-const nestedArray = [1, [2, [3, 4]], [5, 6]];
-console.assert(JSON.stringify(b.deepMap()(double, nestedArray)) === JSON.stringify([2, [4, [6, 8]], [10, 12]]), 'Test for deepMap failed');
\ No newline at end of file
+export default b;
\ No newline at end of file
diff --git a/js/b/b.min.js b/js/b/b.min.js
deleted file mode 100644
index c94132e..0000000
--- a/js/b/b.min.js
+++ /dev/null
@@ -1,4 +0,0 @@
-// eli_oat
-// docs available in the unminified version
-// https://eli.li/_assets/bin/b.js 
-'use strict';const b={curry:function(fn){const curried=(...args)=>{if(args.length>=fn.length){return fn(...args)}else{return(...rest)=>curried(...args,...rest)}}return curried},pipe:(...fns)=>(value)=>fns.reduce((acc,fn)=>fn(acc),value),compose:(...fns)=>(...args)=>fns.reduceRight((res,fn)=>fn(...[].concat(res)),args),identity:x=>x,match:function(){return this.curry((what,s)=>s.match(what))},replace:function(){return this.curry((what,replacement,s)=>s.replace(what,replacement))},filter:function(){return this.curry((f,xs)=>xs.filter(f))},map:function(){return this.curry((f,xs)=>xs.map(f))},deepMap:function(){return this.curry(function deepMap(f,xs){return Array.isArray(xs)?xs.map((x)=>deepMap(f,x)):f(xs)})}};
\ No newline at end of file
diff --git a/js/b/tests.js b/js/b/tests.js
new file mode 100644
index 0000000..62ebf4a
--- /dev/null
+++ b/js/b/tests.js
@@ -0,0 +1,39 @@
+import b from './b';
+
+// Tests! 
+// pipe
+const addOne = (x) => x + 1;
+const double = (x) => x * 2;
+console.assert(b.pipe(addOne, double)(3) === 8, 'Test for pipe failed');
+
+// compose
+console.assert(b.compose(double, addOne)(3) === 8, 'Test for compose failed');
+
+// identity
+console.assert(b.identity(5) === 5, 'Test for identity failed');
+
+// curry
+const add = (x, y) => x + y;
+const curriedAdd = b.curry(add);
+console.assert(curriedAdd(3)(4) === 7, 'Test for curry failed');
+
+// match
+const matchDigits = b.match()(/\d+/g);
+console.assert(JSON.stringify(matchDigits('a1b2c3')) === JSON.stringify(['1', '2', '3']), 'Test for match failed');
+
+// replace
+const censor = b.replace()(/badword/g, '****');
+console.assert(censor('This is a badword in a sentence.') === 'This is a **** in a sentence.', 'Test for replace failed');
+
+// filter
+const isEven = (x) => x % 2 === 0;
+const filterEvens = b.filter()(isEven);
+console.assert(JSON.stringify(filterEvens([1, 2, 3, 4])) === JSON.stringify([2, 4]), 'Test for filter failed');
+
+// map
+const mapDoubles = b.map()(double);
+console.assert(JSON.stringify(mapDoubles([1, 2, 3])) === JSON.stringify([2, 4, 6]), 'Test for map failed');
+
+// deepMap
+const nestedArray = [1, [2, [3, 4]], [5, 6]];
+console.assert(JSON.stringify(b.deepMap()(double, nestedArray)) === JSON.stringify([2, [4, [6, 8]], [10, 12]]), 'Test for deepMap failed');
\ No newline at end of file