/* ----- Задача №2
Створити функцію що повертає масив з 50 випадкових чисел від 0 до 100.
Числа не повинні повторюватись.
Відсортувати масив за зростанням.
Вам може знадобитися Math.random().
*/
/* let arr = []
function getRandomInt(min, max){
for(let i = 0; i < 20; i++){
arr[i] = Math.round( Math.random() * 100 );
}
function filterfunction(item, index){
return arr.indexOf(item) === index;
}
arr.filter(filterfunction);
function sortfunction(a, b){
return a - b;
}
arr.sort(sortfunction)
console.log(arr.sort(sortfunction));
return arr;
}
getRandomInt(0, 100);
*/
/* Реалізуйте функцію isEmpty() яка приймає об’єкт в якості аргумента і повертає true у випадку коли він порожній. Якщо він не порожній чи вам передали не об’єкт функція повинна повертати false. */
/* let obj = {
id: 7,
foo: 'bar'
}
function isEmpty(obj){
console.log(typeof obj)
if(Object.keys(obj).length === 0 && obj.constructor === Object){
console.log(true)
}else{
console.log(false)
}
}
isEmpty(obj); */
/* Маючи масив користувачів (приклад нижче) перетворіть його на об’єкт у якого property будуть ідентифікаторами користувачів, а значеннями самі користувачі за допомогою reduce(). */
let users = [
{
id: 1,
name: 'Mihail'
},
{
id: 2,
name: 'Marina'
},
{
id: 3,
name: 'Andrew'
},
{
id: 4,
name: 'Ilya'
},
];
const categoryPosts = users.reduce((acc, user) => {
let {id, category} = user;
return {...acc, [category]: [...(acc[category] || []), id]};
}, {});
console.log(users)
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.