Skip to content

Instantly share code, notes, and snippets.

View qetr1ck-op's full-sized avatar
😉
Focusing

Orest Prystayko qetr1ck-op

😉
Focusing
View GitHub Profile
'use strict';
function str(strings, ...values) {
let str = "";
values.forEach((val, i) => {
str += strings[i];
str += values[i];
})
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
const addCounter = (list, 0) => {
//return list.concat([0]);
return [...list, 0];
};
const removeCounter = (list, i) => {
/*return list.slice(0, i)
.concat(list.slice(i + 1))*/
return [
...list.slice(0, i),
...list.slice(i + 1)
];
}
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 testAddCounter = () => {
const listBefore = [];
const listAfter = [0];
deepFreeze(listBefore);
expect(
addCounter(listBefore)
).toEqual(listAfter);
};
const toggleTodo = (todo) => {
/*mutated version
todo.completed = !todo.completed;
return todo;*/
/*Object.assing version
return Object.assign({}, todo, {
completed: !todo.completed
});*/
Object.defineProperty(obj, prop, descriptor)
const o1 = {
prop: 'prop'
}
const o2 = Object.setPrototypeOf({
prop2: 'prop2'
}, o1);
console.log(o2.prop2, o2.prop)
function multiple(a, b) {
return a * b;
}
function square(n) {
return multiple(n, n);
}
function printSquare(n) {
console.log(square(n));