Object transformation

Run Settings
LanguageJavaScript
Language Version
Run Command
const treeData = [ { name: 'Москва', expanded: true, children: [{ name: 'Подразделение организации', expanded: true, children: [{ name: 'Аппарат управления', expanded: true, children: [{ name: 'Профсоюзный комитет' }, { name: 'Генеральный директор', expanded: true, children: [{ name: 'Заместитель генерального директора' }, { name: 'Директор по развитию' }, { name: 'Директор по безопасности' }] }, { name: 'Бухгалтерия', expanded: true, children: [{ name: 'Главный бухгалтер' }, { name: 'Заместитель главного бухгалтера' }, { name: 'Договорной отдел' }] }] }] }], } ]; function transformObj(obj, level){ let resObjs = { label: obj.name, value: obj.name, //transliteration key: level }; if (typeof obj == 'object'){ return null; } if (obj.children.length !== 0){ resObj['children'] = []; obj.children.map((child, index) => { resObj['children'].push(transformObj(item, level+index.toString())); }); } return resObj; } let rulesList = []; function rules(data){ if (typeof data !== 'object') { return rulesList; } data.map( item => { rulesList.push(item.name); if (item.children !== 'undefined'){ // console.log(item.children); rules(item.children); } }); return rulesList; } function setRules(data){ rules(data); return rulesList; } const strg = 'Павел Вал Котов Руков Главный p@p.ru 2'; function getUserInfo(str){ return str.split(' '); } const arr= getUserInfo(strg); console.log(setRules(treeData)); // console.log(typeof treeData); // console.log(arr);
let list1 = [{ contractorPrepareFIO: 'Ivanov', contractorPrepare: 'ivanov_ac' }, { contractorPrepareFIO: 'Sidorov', contractorPrepare: 'sidorov_ac' }, { contractorPrepareFIO: 'Pushkin', contractorPrepare: 'pushkin_ac' }, { contractorPrepareFIO: 'Petrov', contractorPrepare: 'petrov_vi' }, { contractorPrepareFIO: 'Medvedev', contractorPrepare: 'medvedev_da' }]; let list2 = [{ contractorPrepareFIO: 'Ivanov', contractorPrepare: 'ivanov_ac' }, { contractorPrepareFIO: 'Pushkin', contractorPrepare: 'pushkin_ac' }]; let persons = list2.map(item => Object.values(item.contractorPrepareFIO).join('')); let available = list1.filter(item => { return persons.indexOf(item.contractorPrepareFIO) === -1 ? true : false; }); console.log(persons); console.log(available);
let profileValues = { ['birth_date']: '01-01-2000', ['city_field']: 'Ekb', // ['nationality_field']: 'Russian', ['staffer_field']: 'staff' }; let userProfileData = {}; if (Boolean(profileValues)) { userProfileData['birth_date'] = profileValues['birth_date']; userProfileData['birth_place'] = profileValues['city_field']; userProfileData['nationality'] = profileValues['nationality_field'] || ''; userProfileData['staffer_bio'] = profileValues['staffer_field']; } console.log(userProfileData);
Editor Settings
Theme
Key bindings
Full width
Lines