This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const compose = (...fns) => (arg) => fns.reduce((composed, f) => f(composed), arg) | |
| const oneSecond = () => 1000 | |
| const getCurrentTime = () => new Date() | |
| const clear = () => { console.clear() } | |
| const log = (message) => { console.log(message) } | |
| const serializeClockTime = date => ({ | |
| hours: date.getHours(), | |
| minutes: date.getMinutes(), | |
| seconds: date.getSeconds() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function showCountDown () { | |
| var nextdate = new Date(2017, 9, 24, 10) | |
| var curDate = new Date() | |
| var seconds, minutes, hours | |
| seconds = Math.floor((nextdate - curDate) / 1000) | |
| minutes = Math.floor(seconds / 60 ) | |
| seconds = seconds % 60 | |
| hours = Math.floor(minutes/60) | |
| minutes = minutes % 60; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.prototype.dup = function (n) { | |
| var arr = [] | |
| for(var i=1;i<=n;i++) { | |
| arr = arr.concat(this) | |
| } | |
| return arr | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function bind (fn, context, params) { | |
| return function callable () { | |
| fn.apply(context, [...params, ...arguments]) | |
| } | |
| } | |
| /* | |
| function foo (a,b,c) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function groupBy (collection, func, callback) { | |
| if (typeof func !== 'function') { | |
| callback('please provide a function to group by') | |
| return | |
| } | |
| if (typeof callback !== 'function') { | |
| callback('please provide a function as a callback') | |
| return | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function head (arr) { | |
| var [start, ...rest] = arr; | |
| return start; | |
| } | |
| function tail (arr) { | |
| var [start, ...rest] = arr; | |
| return rest; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var _ = {pick} | |
| function pick (object, identifierStr) { | |
| var path = identifierStr.split('.') | |
| if (path.length === 1 ) { | |
| return object[path[0]] | |
| } | |
| var [first, ...rest] = path | |
| return pick(object[first], rest.join('.')) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Something = { | |
| cool: function() { | |
| this.greeting = "Hello World"; | |
| this.count = this.count ? this.count + 1 : 1; | |
| } | |
| }; | |
| Something.cool(); | |
| console.log(Something.greeting) | |
| console.log(Something.count); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isRelatedTo (o1, o2) { | |
| function F() {} | |
| F.prototype = o2 | |
| return o1 instanceof F | |
| } | |
| if (!Object.create) { | |
| Object.create = function(o) { | |
| function F(){} | |
| F.prototype = o; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function apply (fn, context, params) { | |
| return fn.call(context, ...params) | |
| } | |
| var obj = {a: 2} | |
| function foo (b,c,d) { | |
| console.log(this.a, b, c, d) | |
| } |