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 arr = [ | |
[10, 10, 10, 20, 60], | |
[10, 10, 50, 10, 10], | |
[20, 10, 30, 20, 10] | |
]; | |
var dest = arr.reduce((acc, cur) => | |
acc.map((el, i) => Math.max(el, cur[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
/** | |
* A collection of helper prototype for everyday DOM traversal, manipulation, | |
* and event binding. Sort of a minimalist jQuery, mainly for demonstration | |
* purposes. MIT @ m3g4p0p | |
*/ | |
window.$ = (function (undefined) { | |
/** | |
* Duration constants | |
* @type {Object} |
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 Subject = function() { | |
let observers = []; | |
return { | |
subscribeObserver(observer) { | |
observers.push(observer); | |
}, | |
unsubscribeObserver(observer) { | |
const index = observers.indexOf(observer); | |
if(index > -1) { |
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
/** | |
* Helper function to swap items in array | |
*/ | |
function swap(arr, firstIndex, secondIndex) { | |
const temp = arr[firstIndex]; | |
arr[firstIndex] = arr[secondIndex]; | |
arr[secondIndex] = temp; | |
} | |
/** |
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 arr = [34, 203, 3, 746, 200, 984, 198, 764, 9]; | |
const merge = (xs, ys) => { | |
if (xs.length === 0) return ys; | |
if (ys.length === 0) return xs; | |
const x = xs[0]; | |
const y = ys[0]; | |
return (x < y) | |
? [x, ...merge(xs.slice(1), ys)] |
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 = (function(){ | |
var topics = {}; | |
var hOP = topics.hasOwnProperty; | |
return { | |
subscribe: function(topic, listener) { | |
// Create the topic's object if not yet created | |
if(!hOP.call(topics, topic)) topics[topic] = []; | |
// Add the listener to queue |
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 pipeline = (seed, ...fns) => fns.reduce((val, fn) => fn(val), seed); | |
console.log(pipeline()); // undefined | |
console.log(pipeline(42)); // 42 | |
console.log(pipeline(42, n => n*2, n => -n)); // -84 |
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) => | |
(seed) => | |
fns.reduceRight((val, fn) => fn(val), seed); | |
const greet = name => `Hi, ${name}`; | |
const exclaim = statement => `${statement.toUpperCase()}!`; | |
const welcome = compose(greet, exclaim); | |
console.log(welcome('Yozh')); // 'Hi, YOZH!' |
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 peopleFactory = function(name, age, sex) { | |
return { | |
name, | |
age, | |
sex, | |
}; | |
}; | |
const human01 = peopleFactory('Alex', 28, 'male'); |
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
window.onload = function() { | |
paintPonit(document.body, 'click', function(event) { | |
if (event.target.nodeName === 'I') { | |
event.target.className = 'clicked'; | |
} | |
}); | |
function paintPonit(obj, eventName, handler) { | |
const handlerWrapper = event => handler.call(obj, event); | |
obj.addEventListener(eventName, handlerWrapper, false); |