commit 6625e5ccd3104598b41138e0d7f1198cc1796af5 Author: neingeist Date: Thu Jun 30 19:55:37 2016 +0200 initial commit diff --git a/currying.js b/currying.js new file mode 100644 index 0000000..862a228 --- /dev/null +++ b/currying.js @@ -0,0 +1,12 @@ +function converter(toUnit, factor, offset, input) { + offset = offset || 0; + return [((offset+input)*factor).toFixed(2), toUnit].join(" "); +} + +var milesToKm = converter.curry('km',1.60936,undefined); +var poundsToKg = converter.curry('kg',0.45460,undefined); +var farenheitToCelsius = converter.curry('degrees C',0.5556, -32); + +milesToKm(10); // returns "16.09 km" +poundsToKg(2.5); // returns "1.14 kg" +farenheitToCelsius(98); // returns "36.67 degrees C" diff --git a/truthy-falsy.js b/truthy-falsy.js new file mode 100644 index 0000000..37b4022 --- /dev/null +++ b/truthy-falsy.js @@ -0,0 +1,24 @@ +http://www.sitepoint.com/javascript-truthy-falsy/ + +function assert(condition, message) { + if (!condition) { + throw message || "Assertion failed"; + } +} + +// XXX == false +// +// falsy +assert(!(false)); +assert(!(0)); +assert(!("")); +assert(!(null)); +assert(!(undefined)); +assert(!(NaN)); + +// truthy +assert(!!("0")); +assert(!!("false")); +// empty functions +// empty array +// empty object