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
Object.defineProperty(obj, prop, descriptor) |
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 toggleTodo = (todo) => { | |
/*mutated version | |
todo.completed = !todo.completed; | |
return todo;*/ | |
/*Object.assing version | |
return Object.assign({}, todo, { | |
completed: !todo.completed | |
});*/ |
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 testAddCounter = () => { | |
const listBefore = []; | |
const listAfter = [0]; | |
deepFreeze(listBefore); | |
expect( | |
addCounter(listBefore) | |
).toEqual(listAfter); | |
}; |
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 incrementCounter = (list, i) => { | |
/*return list.slice(0, i) | |
.concat(list[i] + 1) | |
.concat(list.slice(i + 1));*/ | |
return [ | |
...list.slice(0, i), | |
list[i] + 1, | |
...list.slice(i + 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
const removeCounter = (list, i) => { | |
/*return list.slice(0, i) | |
.concat(list.slice(i + 1))*/ | |
return [ | |
...list.slice(0, i), | |
...list.slice(i + 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
const addCounter = (list, 0) => { | |
//return list.concat([0]); | |
return [...list, 0]; | |
}; |
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 counter = (state = 0, action) => { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMENT': | |
return state - 1; | |
default: | |
return state; | |
} | |
} |
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
'use strict'; | |
function str(strings, ...values) { | |
let str = ""; | |
values.forEach((val, i) => { | |
str += strings[i]; | |
str += values[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
describe(name, function() { ... }) | |
it(name, function() { ... }) | |
assert.equal(value1, value2) |
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 module = angular.module('uploader', []); | |
module.service('uploader', ['$q', function($q) { | |
function readyStateChange(deferred, xhr) { | |
if(xhr.readyState == 4) { | |
if(xhr.status == 200) { | |
deferred.resolve(JSON.parse(xhr.responseText)); | |
} | |
else { | |
deferred.reject('HTTP status ' + xhr.status); |