zaliczenia

mail@pastecode.io avatar
unknown
typescript
2 years ago
1.8 kB
3
Indexable
Never
//Zadanie 1.
const arr: number[] = Array.from({ length: 10 }, () => Math.floor(Math.random() * 10));
const reversedAndEven: number[] = arr.filter((num) => num % 2 == 0).reverse();

//Zadanie 2.
let names: {firstName: string, lastName: string}[] = [
  {
    firstName: "Olaf",
    lastName: "Nowak",
  },
];

const addUser = (fName: string, lName: string, arr: Object[]) => arr.push({ firstName: fName, lastName: lName });

addUser("Ola", "Woźniak", names);
addUser("Mateusz", "Marciniak", names);
addUser("Ola", "Apollo", names);
addUser("Olaf", "Nowak", names);
addUser("Alojzy", "Szczęsny", names);
addUser("Olaf", "Wójcik", names);
addUser("Czesław", "Gieroj", names);
addUser("Ola", "Wysocka", names);
addUser("Olaf", "Dobry", names);

names.forEach((element) => (element.firstName == "Ola") ? console.log(element) : null);


//Zadanie 3.
let names: { firstName: string; lastName: string }[] = [
  {
    firstName: "Olaf",
    lastName: "Nowak",
  },
];

const addUser = (fName: string, lName: string, arr: Object[]) =>
  arr.push({ firstName: fName, lastName: lName });

addUser("Ola", "Woźniak", names);
addUser("Mateusz", "Marciniak", names);
addUser("Ola", "Jóźwik", names);
addUser("Olaf", "Nowak", names);
addUser("Alojzy", "Szczęsny", names);
addUser("Olaf", "Wójcik", names);
addUser("Czesław", "Nowak", names);
addUser("Ola", "Wysocka", names);
addUser("Olaf", "Dobry", names);

let count: number = 0;
names.forEach((element) => (element.firstName == "Ola" ? (console.log(element), count++) : false));
console.log(count);


//Zadanie 4.
const arr: number[] = Array.from({ length: 10 }, () => Math.floor(Math.random() * 10));
const arrWithHighestValues = (arr: number[]) => arr.sort((a, b) => b - a).slice(0, 3);
console.log(arr)
console.log(arrWithHighestValues(arr))