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 binToDec(n) { | |
| var result = 0; | |
| var s = n.toString(); | |
| var len = s.length - 1; | |
| for (var i = len; i >= 0; i--) { | |
| result += s[i] * Math.pow(2, len-i); | |
| } | |
| return result; | |
| } |
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 ( $ ) { | |
| var invalidations = [ 'invalidRequiredField', 'invalidInput' ]; | |
| invalidations.invalidRequiredField = function invalidRequiredField(params) { | |
| return params.isRequiredField && !params.value; | |
| }; | |
| invalidations.invalidInput = function invalidInput(params) { | |
| var isRequiredField = params.isRequiredField, |
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
| /** | |
| * Flattens native JS Array objects. | |
| * Uses the native Array.isArray method, therefore array like objects (e.g Arguments object) need to be converted to Array | |
| * instances for this function to work on them (e.g ...arguments) | |
| * @param {Array} list | |
| * @param {Array} newList - not required for the first call of function | |
| * @return {Array} newList | |
| */ | |
| function flatten(list, newList = []) { | |
| for (var i = 0, length = list.length; i < length; i++) { |
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
| import classPrfx from 'postcss-class-prefix'; | |
| import precss from 'precss'; // for scss support | |
| module: { | |
| loaders: [ | |
| { | |
| test: /\.scss$/, | |
| loaders: [ | |
| 'style', | |
| 'css', |
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 prefixFactory(prefix) { | |
| return function prefixer(string) { | |
| return string.split(' ') | |
| .map( s => prefix + s) | |
| .join(' '); | |
| }; | |
| } | |
| export default prefixFactory; |
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
| process.stdin.setEncoding('utf8'); | |
| process.stdin.on('data', function (buf) { | |
| var tokens = formatInput(buf); | |
| var a = parseInt(tokens[0]); | |
| var b = parseInt(tokens[1]); | |
| console.log(a+b); | |
| process.exit(); | |
| }); | |
| function formatInput(input) { |
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 Events = { | |
| on: function(type, fn, context) { | |
| this.events = this.events || {}; | |
| this.events[type] = this.events[type] || []; | |
| fn = typeof fn === 'function' ? fn : context[fn]; | |
| this.events[type].push({ fn: fn, context: context || this }); | |
| return this.off.bind(this, type, fn, context); | |
| }, |
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
| // Simple JavaScript Templating | |
| // John Resig - http://ejohn.org/ - MIT Licensed | |
| // http://ejohn.org/blog/javascript-micro-templating/ | |
| (function() { | |
| var cache = {}; | |
| function tmpl(str, data){ | |
| // Figure out if we're getting a template, or if we need to | |
| // load the template - and be sure to cache the result. | |
| var fn = !/\W/.test(str) ? |
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
| // 0 based index | |
| var iParent = (i) => Math.floor((i-1)/2); | |
| var iLeftChild = (i) => 2*i + 1; | |
| var iRightChild = (i) => 2*i + 2; | |
| function heapsort(list, count) { | |
| // first build a heap | |
| maxHeapify(list, 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
| const INIT = 'INIT'; | |
| function createStore(reducer, initialState) { | |
| var state = initialState; | |
| var subscribers = []; | |
| function getState() { | |
| return state; | |
| } | |
| function dispatch(action) { |