One Paragraph of project description goes here
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
| const flipAndCurry = (fn) => | |
| (first) => (second) => fn(second, first); | |
| // Example: | |
| // https://gist.github.com/stefanfrede/596597d8b544de08491364eab20053c6 | |
| const mapWith = flipAndCurry(map); | |
| // flipAndCurry throws the current context away, so it can’t be used to flip methods. | |
| // A small alteration gets the job done: | |
| const flipAndCurry = (fn) => |
| // Copy an object by extending an empty object: | |
| Object.assign({}, { | |
| apples: 12, | |
| oranges: 12 | |
| }) | |
| //=> { apples: 12, oranges: 12 } | |
| // Extend one object with another: | |
| const inventory = { | |
| apples: 12, |
| const memoized = (fn) => { | |
| const lookupTable = {}; | |
| return function (...args) { | |
| const key = JSON.stringify(this, args); | |
| return lookupTable[key] || (lookupTable[key] = fn.apply(this, args)); | |
| } | |
| } |
| const getWith = (attr) => (object) => object[attr] | |
| /** | |
| * Examples: | |
| */ | |
| const inventory = { | |
| apples: 0, | |
| oranges: 144, | |
| eggs: 36 | |
| }; |
| const pluckWith = (attr) => mapWith(getWith(attr)); | |
| // or even better | |
| const pluckWith = compose(mapWith, getWith); | |
| /** | |
| * Example | |
| */ | |
| const inventories = [ |
| const deepMapWith = (fn) => | |
| function innerdeepMapWith (tree) { | |
| return Array.prototype.map.call(tree, (element) => | |
| Array.isArray(element) | |
| ? innerdeepMapWith(element) | |
| : fn(element) | |
| ); | |
| } | |
| /** |
| /** | |
| * Simple [local|session]Storage with Cookie Fallback | |
| * v.1.2.0 | |
| * | |
| * USAGE: | |
| * ---------------------------------------- | |
| * Set New / Modify: | |
| * store({ | |
| * storage: { | |
| * key: 'my_key', |
| function uuidv4() { | |
| return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => | |
| (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) | |
| ) | |
| } | |
| console.log(uuidv4()); |
| // Example returns for illustration only. | |
| const cases = { | |
| alpha() { | |
| return [ "Alpha", arguments.length ]; | |
| }, | |
| beta() { | |
| return [ "Beta", arguments.length ]; | |
| }, | |
| _default() { | |
| return [ "Default", arguments.length ]; |