initial commit
This commit is contained in:
commit
6625e5ccd3
2 changed files with 36 additions and 0 deletions
12
currying.js
Normal file
12
currying.js
Normal file
|
@ -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"
|
24
truthy-falsy.js
Normal file
24
truthy-falsy.js
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue