Skip to content

Instantly share code, notes, and snippets.

Object.defineProperty(obj, prop, descriptor)
const toggleTodo = (todo) => {
/*mutated version
todo.completed = !todo.completed;
return todo;*/
/*Object.assing version
return Object.assign({}, todo, {
completed: !todo.completed
});*/
const testAddCounter = () => {
const listBefore = [];
const listAfter = [0];
deepFreeze(listBefore);
expect(
addCounter(listBefore)
).toEqual(listAfter);
};
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)
]
const removeCounter = (list, i) => {
/*return list.slice(0, i)
.concat(list.slice(i + 1))*/
return [
...list.slice(0, i),
...list.slice(i + 1)
];
}
const addCounter = (list, 0) => {
//return list.concat([0]);
return [...list, 0];
};
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
'use strict';
function str(strings, ...values) {
let str = "";
values.forEach((val, i) => {
str += strings[i];
str += values[i];
})
@qetr1ck-op
qetr1ck-op / bdd.js
Last active December 7, 2015 19:02
describe(name, function() { ... })
it(name, function() { ... })
assert.equal(value1, value2)
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);