Object.values(array.reduce((acc, item, i) => {
const { date, schedule, _data } = item;
const { teachers, subjs } = _data;
if (!acc.hasOwnProperty(date)) acc[date] = item
else {
acc[date].schedule = [ ...acc[date].schedule, ...schedule];
acc[date]._data.teachers = [...acc[date]._data.teachers, ...teachers];
acc[date]._data.subjs = [...acc[date]._data.subjs, ...subjs];
}
return acc;
}, {}))
let url = 'https://jsonplaceholder.typicode.com/users';
async function getUsers(url) {
const response = await fetch(url)
const result = await response.json()
const usersID = result.reduce((acc, item) => {
const { id } = item;
acc.push(['id', id])
return acc
}, [])
console.log(usersID)
}
getUsers(url)
const arr = [
{
contry: 'Russia',
name: 'Alex',
age: '34',
},
{
contry: 'Russia',
name: 'July',
age: '22',
},
{
contry: 'USA',
name: 'Tom',
age: '32',
},
{
contry: 'USA',
name: 'Jack',
age: '74',
},
]
arr.reduce((acc, item) => {
const { contry, name, age } = item;
if(!acc.hasOwnProperty(contry)) acc[contry] = {[name]:age}
else acc[contry] = {...acc[contry], [name]: age}
return acc
}, {})
const app = async () => {
const obj = await fetch('https://jsonplaceholder.typicode.com/posts/');
const result = await obj.json();
console.log(result[0])
}
app()
const data = [
{
id: 1,
name: "краски"
},
{
id: 1,
name: "краски"
},
{
id: 2,
name: "краски"
},
{
id: 1,
name: "краски"
},
]
Object.values(data.reduce((acc, item) => {
const { id } = item
if(!acc.hasOwnProperty(id)) acc[id] = { ...item, count: 1};
else acc[id].count += 1
return acc
}, {}))
const data = [
{ name: 'Sasha', apple: 8, banana: 6, cherry: 9 },
{ name: 'Artur', apple: 4, banana: 2, cherry: 1 },
{ name: 'Sasha', apple: 5, banana: 7, cherry: 3 },
{ name: 'Bogdan', apple: 6, banana: 11, cherry: 8 },
{ name: 'Artur', apple: 8, banana: 6, cherry: 9 },
];
data.reduce((acc, item) => {
const { name, ...rest } = item;
if (!acc.hasOwnProperty(name)) acc[name] = { ...rest };
else {
const keys = Object.keys(rest);
keys.forEach(key => acc[name][key] += rest[key])
}
return acc
}, {})
const Button = ({ handler }) => (
<button onClick={handler}>Нажми на меня</button>
);
const App = () => {
const [element, setElement] = useState(1000000);
const handler = () => {
setElement(element - 1);
};
return (
<div className="page" id="page">
<div className="element">{element}</div>
<Button handler={handler} />
</div>
);
};
document.querySelector('#category').addEventListener('click', ({ target }) => {
const category = ["genre", "type", "long", "country", "awards", "result", "actor"];
const { id } = target;
const categoryName = id.split('-').pop();
if (!category.includes(categoryName)) return;
document.querySelector(`#subcategory-block-${categoryName}`).classList.toggle('active');
document.querySelector(`#menu-figure-${categoryName}`).classList.toggle('activeForMenuFigure');
})