@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).
Here we go with the explanations:
(function(x, f = () => x) {
/** | |
* Dependencies | |
*/ | |
const sortBy = require('sort-by'); | |
/** | |
* Representing an election as a data structure | |
*/ | |
const votes = [ | |
{ id: 0, voterId: 'a', zone: 'Oslo', party: 'Miljøpartiet De Grønne' }, |
export class SyncPath { | |
constructor(rootRef, path) { | |
this._rootRef = rootRef; | |
this.user = this._rootRef.getAuth(); | |
this._userDataRef = this._rootRef.child(path).child(this.user.uid); | |
this.data = {}; | |
this._userDataRef.on('value', (snap) => this.data = snap.val() || {}); | |
} | |
keys() { | |
return Object.keys(this.data); |
@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).
Here we go with the explanations:
(function(x, f = () => x) {
// Just paste this into the console on http://www.jshint.com/docs/options/ | |
(function() { | |
var i, row, link, span, extraCol, checkbox, value; | |
var rows = document.querySelectorAll('table.options tr'); | |
var links = document.querySelectorAll('table.options a'); | |
// add checkboxes | |
for (var i = 0; i < rows.length; i++) { | |
row = rows[i]; |
var Firebase = require("./firebase-node.js"); | |
function Queue(ref) { | |
this._ref = ref; | |
} | |
Queue.prototype.pop = function(cb) { | |
this._ref.startAt().limit(1).once("child_added", this._pop.bind(this, cb)); | |
} |
#!/bin/bash | |
# TODO: skip tiny files (so small they couldn't be photos) | |
# TODO: make sure sym links and other file system oddities are handled | |
# | |
# Constants | |
# | |
CHAR_COUNT=12 | |
BLOCK_COUNT=6 | |
SKIP_SIZE=3 # Every new block is sampled by skipping this amount of blocks to the next position |
'use strict'; | |
const { createStore, applyMiddleware } = require('./redux'); | |
const { addActionTakersToStore, addLoggingToStore } = require('./middleware'); | |
const { EventEmitter } = require('events'); | |
const { | |
isPromise, | |
isFunction, | |
isObject, |
function composeLeft(...funcs) { | |
return function(input) { | |
return funcs.reduce((result, func) => { | |
return func(result); | |
}, input); | |
} | |
} | |
function composeRight(...funcs) { | |
return function(input) { |
'use strict'; | |
/** | |
* Dependencies | |
*/ | |
const expect = require('expect'); | |
/** | |
* Factory for creating an effects handling "runtime" | |
* that stores a retrievable effects log |
// function that creates an async operation that can either fail or succeed based on the argument (bool) | |
const createAsyncOperation = (opName) => (succeeds) => !succeeds ? Promise.resolve(opName + ' success') : Promise.reject(new Error(opName + ' failure')); | |
// corrective operations are operations that | |
// sematically undo the original operation | |
// | |
// i.e - you cannot unsend an email or delete the booking at an hotel, | |
// but you can send an apology email and cancel a reservation | |
// | |
// to enable (unlimited) of both operations and corrective operations |