Size: a a a

2021 January 06

DP

Dmitry Pripa in pro.js
Они оба пустые, но разные
источник

DP

Dmitry Pripa in pro.js
Отдельные инстансы
источник

Д

Да in pro.js
Dmitry Pripa
Отдельные инстансы
Спасибо
источник

Д

Да in pro.js
но по мне странновато немного
источник

t

th.witness in pro.js
Да
но по мне странновато немного
🤔
источник

DP

Dmitry Pripa in pro.js
Ничего странного, все отлично как раз, так работает ооп
источник

С

Славик in pro.js
Да
это как?
есть примитивные типа данные, а есть не примитивные (объекты)
источник

С

Славик in pro.js
примитивные сравниваются по значению, объекты по ссылке
источник

DP

Dmitry Pripa in pro.js
У массива не просто так есть свои методы
источник

DT

D_d Tch in pro.js
вопрос. как превратить первый массив во второй?
const simplaArr = [
{year: '1988', title: 'tile1', location: 'b'},

{year: '1988', title: 'title2', location: 'a'},

{year: '1989', title: 'title3', location: 'c'}
];
=>
const simpleArr2 = [
{
   year: '1988',
   places: [
       {title: 'title1', location: 'b'},
       {title: 'title2', location: 'a'},
   ]
},
{
   year: '1989',
   places: [{title: 'title3', location: 'c'}]
}]
источник

S

Syntax Highlight Bot in pro.js
D_d Tch
вопрос. как превратить первый массив во второй?
const simplaArr = [
{year: '1988', title: 'tile1', location: 'b'},

{year: '1988', title: 'title2', location: 'a'},

{year: '1989', title: 'title3', location: 'c'}
];
=>
const simpleArr2 = [
{
   year: '1988',
   places: [
       {title: 'title1', location: 'b'},
       {title: 'title2', location: 'a'},
   ]
},
{
   year: '1989',
   places: [{title: 'title3', location: 'c'}]
}]
источник

DP

Dmitry Pripa in pro.js
reduce
источник

DP

Dmitry Pripa in pro.js
Вроде как решает такую задачу же
источник

EP

Evgenii Popov in pro.js
D_d Tch
вопрос. как превратить первый массив во второй?
const simplaArr = [
{year: '1988', title: 'tile1', location: 'b'},

{year: '1988', title: 'title2', location: 'a'},

{year: '1989', title: 'title3', location: 'c'}
];
=>
const simpleArr2 = [
{
   year: '1988',
   places: [
       {title: 'title1', location: 'b'},
       {title: 'title2', location: 'a'},
   ]
},
{
   year: '1989',
   places: [{title: 'title3', location: 'c'}]
}]
Может так:
const simpleArr = [
 { year: "1988", title: "tile1", location: "b" },
 { year: "1988", title: "title2", location: "a" },
 { year: "1989", title: "title3", location: "c" }
];
const newObj = {};
simpleArr.forEach((el) => {
 const year = el.year;
 const t = el.title;
 const loc = el.location;
 if (!Array.isArray(newObj[year])) newObj[year] = [];
 newObj[year].push({ title: t, location: loc });
});
const result =[]
for(let year in newObj){
 result.push({ year: year, places: newObj[year] })
}
console.log(result)

reduce - не знаю как тут им
источник

S

Syntax Highlight Bot in pro.js
Evgenii Popov
Может так:
const simpleArr = [
 { year: "1988", title: "tile1", location: "b" },
 { year: "1988", title: "title2", location: "a" },
 { year: "1989", title: "title3", location: "c" }
];
const newObj = {};
simpleArr.forEach((el) => {
 const year = el.year;
 const t = el.title;
 const loc = el.location;
 if (!Array.isArray(newObj[year])) newObj[year] = [];
 newObj[year].push({ title: t, location: loc });
});
const result =[]
for(let year in newObj){
 result.push({ year: year, places: newObj[year] })
}
console.log(result)

reduce - не знаю как тут им
источник

В

Виктория in pro.js
D_d Tch
вопрос. как превратить первый массив во второй?
const simplaArr = [
{year: '1988', title: 'tile1', location: 'b'},

{year: '1988', title: 'title2', location: 'a'},

{year: '1989', title: 'title3', location: 'c'}
];
=>
const simpleArr2 = [
{
   year: '1988',
   places: [
       {title: 'title1', location: 'b'},
       {title: 'title2', location: 'a'},
   ]
},
{
   year: '1989',
   places: [{title: 'title3', location: 'c'}]
}]
Object.values(simplaArr.reduce((map, { year, ...place }) =>
 Object.assign(map, {
       [year]: {
           year, places: (
               map[year] &&
               map[year].places || []
           ).concat(place)
       }
   }), {}
))
источник

S

Syntax Highlight Bot in pro.js
Виктория
Object.values(simplaArr.reduce((map, { year, ...place }) =>
 Object.assign(map, {
       [year]: {
           year, places: (
               map[year] &&
               map[year].places || []
           ).concat(place)
       }
   }), {}
))
источник

EP

Evgenii Popov in pro.js
Виктория
Object.values(simplaArr.reduce((map, { year, ...place }) =>
 Object.assign(map, {
       [year]: {
           year, places: (
               map[year] &&
               map[year].places || []
           ).concat(place)
       }
   }), {}
))
Круто, пойду учить)))
источник

DT

D_d Tch in pro.js
Виктория
Object.values(simplaArr.reduce((map, { year, ...place }) =>
 Object.assign(map, {
       [year]: {
           year, places: (
               map[year] &&
               map[year].places || []
           ).concat(place)
       }
   }), {}
))
Nice 👌) очень не плохое решение)
источник

SM

Semantic Massive in pro.js
Всем привет, ищу на удаленный фултайм:
- frontend developers with WordPress experience (=Linux, Apache, PHP, MySQL, CSS, APIs via CURL)
- backend Java developers (=Linux, Tomcat, Java, MySQL, Cloud APIs)
Оплата $800-1200 в месяц
Пишите в ЛС
источник