children
даже если пустой:function unFlatten(array) {
const childrenMap = Object.create(null);
for(const item of array) {
if(item.parent in childrenMap)
childrenMap[item.parent].push(item);
else
childrenMap[item.parent] = [item];
if(!childrenMap[item.id]) childrenMap[item.id] = [];
item.children = childrenMap[item.id];
};
return childrenMap[null]
}
children
только там где нужны.function unFlatten(array) {
const childrenMap = Object.create(null);
const secondPass = [];
for(const item of array) {
if(item.parent in childrenMap)
childrenMap[item.parent].push(item);
else
childrenMap[item.parent] = [item];
if(item.id in childrenMap)
item.children = childrenMap[item.id];
else
secondPass.push(item)
};
for(const item of secondPass) {
if(item.id in childrenMap)
item.children = childrenMap[item.id];
};
return childrenMap[null]
}
function unFlatten(array) {
const map = Object.create(null);
const secondPass = [];
for(const item of array) {
map[item.id] = item;
if(item.parent in map) {
if('children' in map[item.parent])
map[item.parent].children.push(item)
else
map[item.parent].children = [item];
} else {
secondPass.push(item);
}
};
for(const item of secondPass) {
if(item.parent in map) {
if('children' in map[item.parent])
map[item.parent].children.push(item)
else
map[item.parent].children = [item];
}
};
return secondPass
}
function toObject(animals, titles, list) {
animals = Object.fromEntries(animals);
titles = Object.fromEntries(titles);
return list.map(([animal, title, ...array], i) => ({
id: i + 1,
title: titles[title],
animal: animals[animal],
array
}));
}
toObject(arr1, arr2, arr3);
key
в v-for
попадаются дубликаты, но обычно это приводит к другим ошибкам. localStorage
хранятся только строки. Если вы делаете так localStorage.setItem('token', false)
, то при localStorage.getItem('token')
вы получаете не ''
, а результат приведения false
к строке, т.е. 'false'.
false !== ''
- тоже истина, потому что !==
сравнение без приведения типов. import()
поддерживает использование переменных, при этом в бандл попадают все файлы соответствующие паттерну.webpack
всё равно не знает, что у вас там лежит в config
. Он не запускает ваш код - он его собирает.`~static/i18n/CONFIG_LANG.json`: path.resolve(`./static/i18n/${config.lang}.json`)
и в коде, соответственно, писать: import default_locale from `~static/i18n/CONFIG_LANG.json`
Symbol(<имя>)
- создание нового символа. Чтобы получить значение по сиволу, надо иметь на руках ссылку на этот сиvвол. Из документации:Symbol("foo") === Symbol("foo"); // false
setTimeout(function() {
partner_window.close();
location.href = 'https://betta.com';
}, 2000);
->setTimeout(function() {
partner_window.close();
}, 500);
setTimeout(function() {
location.href = 'https://betta.com';
}, 2000);
This SDK is intended for end-user client access from environments such as the Web, mobile Web (e.g. React Native, Ionic), Node.js desktop (e.g. Electron), or IoT devices running Node.js. If you are instead interested in using a Node.js SDK which grants you admin access from a privileged environment (like a server), you should use the Firebase Admin Node.js SDK.
The Firebase Admin Node.js SDK enables access to Firebase services from privileged environments (such as servers or cloud) in Node.js.
const newData = JSON.parse(
JSON.stringify(data),
(key, value) => key === 'value' ? 'new value' : value
);