This file contains 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
class IterableIterator { | |
constructor(obj){ | |
this.index = 0 | |
this.data = Object.keys(obj).map((key) => { return { [key]: obj[key] } }) | |
} | |
next = () => { | |
if(this.index < this.data.length){ | |
return { value: this.data[this.index++], done: false } | |
} else { | |
this.index = 0 |
This file contains 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
// An object that respects the iterable protocol | |
var anIterableObject = { | |
[Symbol.iterator]: function(){ return something } | |
}; | |
// An object that respects the iterator protocol and the iterable protocol | |
var anIterableIterator = { | |
next: function() { return {value: somevalue, done: trueorfalse }, | |
[Symbol.iterator]: function(){ return something } | |
} |
This file contains 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
// @@iterator method | |
| Property | Value | |
---------------------------------------------------------------------------------------------------------------- | |
[Symbol.iterator] | A zero arguments function that returns an object, conforming to the iterator protocol | |
---------------------------------------------------------------------------------------------------------------- | |
This file contains 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
let ob = { age: 41, name: 'Leonard', profession: 'JavaScript Developer' }; | |
let looped = [] | |
for(const key of Object.keys(ob)){ | |
looped.push({ [key]: ob[key] }) | |
} |
This file contains 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
let ob = { age: 41, name: 'Leonard', profession: 'JavaScript Developer' }; | |
let properties = Object.keys(ob).map((key) => { | |
return { [key]: ob[key] } | |
}); // returns [ { age: 41 }, { name: 'Leonard' }, { profession: 'JavaScript Developer' } ] |
This file contains 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
let ob = { age: 41, name: 'Leonard', profession: 'JavaScript Developer' }; | |
let obit = iteratorFactory(ob); | |
obit.next(); // returns { value: { age: 41 }, done: false } | |
obit.next(); // returns { value: { name: 'Leonard'}, done: false } | |
obit.next(); // returns { value: { profession: 'JavaScript Developer'}, done: false } | |
obit.next(); // returns { value: undefined, done: true } | |
for(const o of obit){ | |
console.log(o); | |
} // Throws | |
// Uncaught TypeError: obit is not iterable |
This file contains 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
let ob = { age: 41, name: 'Leonard', profession: 'JavaScript Developer' }; | |
let obit = iteratorFactory(ob); | |
obit.next(); // returns { value: { age: 41 }, done: false } | |
obit.next(); // returns { value: { name: 'Leonard'}, done: false } | |
obit.next(); // returns { value: { profession: 'JavaScript Developer'}, done: false } | |
obit.next(); // returns { value: undefined, done: true } |
This file contains 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 iteratorFactory(obj) { | |
var nextIndex = 0; | |
var keys = Object.keys(obj); | |
var end = keys.length; | |
var next = function(){ | |
return nextIndex < end ? { value: { [keys[nextIndex]]: obj[keys[nextIndex++]]}, done: false } : { value: undefined, done: true } | |
} | |
return { next: next }; | |
} |
This file contains 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
# Asset cleaning | |
# Clean old assets leaving three most recent versions of assets | |
rake assets:clean | |
# Nuke old assets | |
rake assets:clobber |
This file contains 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
// Email Regex lifted from Parsely.js: | |
var regexp = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i | |
// The regex above handles all the standard characters to |
NewerOlder