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 calcSum = list => list.reduce((acc, val) => acc + val, 0); | |
const cumulativeSum = (list, acc = []) => { | |
if (!list.length) return acc; | |
const sum = calcSum(list), | |
subset = list.slice(0, list.length - 1); | |
return cumulativeSum(subset, [sum, ...acc]); |
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 obj1 = { | |
field: { | |
key: "foo" | |
} | |
}; | |
const obj2 = { | |
field: obj1.field | |
} |
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 store = { | |
namespaced: true, | |
state: { | |
users: [], | |
posts: [] | |
}, | |
mutations: { | |
set(state, { name, data }) { | |
state[name] = data; | |
}, |
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
<template> | |
<div> | |
<form @submit.prevent="addUser"> | |
<input type="text" v-model="form.name" /> | |
<button type="submit">Add user</button> | |
</form> | |
<ul> | |
<li :key="user.id" v-for="user in users">{{user.name}}</li> | |
</ul> | |
</div> |
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
// Original data | |
{ | |
"data": { | |
"level1": { | |
"field1": "data 1 on level 1", // changed | |
"level2": { | |
"field1": "data 1 on level 2", | |
"level3": { | |
"field1": "data 1 on level 3", //changed | |
"field2": "data 2 on level 3" |
OlderNewer