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
[1,1,2,2].filter(function(value, index, self) { | |
return self.indexOf(value) === index; | |
}); |
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 shorten(options) { | |
var item = $(options.selector); | |
var sourceText = $(item).text().trim(); | |
var firstSection = sourceText.substring(0, options.textLength); | |
var lastSection = sourceText.substring(options.textLength, sourceText.length); | |
var firstItem = $('<span>'); | |
firstItem.text(firstSection); | |
var readMoreItem = $('<a>'); |
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
var chai = require('chai'); | |
var expect = chai.expect; | |
var sinon = require('sinon'); | |
var sinonChai = require('sinon-chai'); | |
chai.use(sinonChai); | |
var eventBus = (function () { | |
var _eventHandler = null; |
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
var expect = require('chai').expect; | |
// store | |
const createStore = (reducer) => { | |
let listeners = []; | |
let state; | |
const getState = () => state; | |
const subscribe = (listener) => { |
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
// 1: template strings - basics | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('a template string, is wrapped in ` (backticks) instead of \' or "', function() { | |
describe('by default, behaves like a normal string', function() { | |
it('just surrounded by backticks', function() { | |
var str = `like a string`; | |
assert.equal(str, 'like a string'); |
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
// 2: template strings - multiline | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('template string, can contain multiline content', function() { | |
it('a normal string can`t span across multiple lines', function() { | |
var normalString = 'line1' + | |
'\n' + | |
'line2'; | |
assert.equal(normalString, 'line1\nline2'); |
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
// 3: template strings - tagged | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('tagged template strings, are an advanced form of template strings', function() { | |
it('syntax: prefix the template string with a function to call (without "()" around it)', function() { | |
function tagFunction(s) { | |
return s.toString(); | |
} | |
var evaluated = tagFunction `template string`; |
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
// 4: template strings - String.raw | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('on tagged template strings you can use the `raw` property like so `s.raw`', function() { | |
it('the `raw` property accesses the string as it was entered', function() { | |
function firstChar(strings) { | |
return strings.raw; | |
} | |
assert.equal(firstChar`\n`, '\\n'); |
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
// 5: arrow functions - basics | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('arrow functions', function() { | |
it('are shorter to write', function() { | |
var func = () => { | |
return 'I am func'; | |
}; | |
assert.equal(func(), 'I am func'); |
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
// 6: arrow functions - binding | |
// To do: make all tests pass, leave the asserts unchanged! | |
class LexicallyBound { | |
getFunction() { | |
return () => this | |
} | |
getArgumentsFunction() { |
OlderNewer