hinzugefügt find, flat, flaMap, some,every Methoden. Bearbeitet Objekte aus dem Template-Script

This commit is contained in:
David 2022-11-07 20:16:34 +01:00
parent b274906134
commit ae6887379b
4 changed files with 118 additions and 2 deletions

View File

@ -0,0 +1,48 @@
const randomIntNumbers = n => {
let transaktionen = [];
for (let i = 0; i < n; i++) {
const rndNum = Math.random() * 1000;
rndNum > Math.random() * 1000
? transaktionen.push(Math.trunc(rndNum))
: transaktionen.push(-Math.trunc(rndNum));
}
return transaktionen;
};
const movements = randomIntNumbers(16);
const account1 = {
owner: "David Aster",
movements: [200, 450, -400, 3000, -650, -130, 70, 1300],
interestRate: 1.2, // %
pin: 1111,
};
const account2 = {
owner: "Joanne Aster",
movements: [5000, 3400, -150, -790, -3210, -1000, 8500, -30],
interestRate: 1.5,
pin: 2222,
};
const account3 = {
owner: "Steven Schmidt",
movements: [200, -200, 340, -300, -20, 50, 400, -460],
interestRate: 0.7,
pin: 3333,
};
const account4 = {
owner: "Elvis Presley",
movements: [430, 1000, 700, 50, 90],
interestRate: 1,
pin: 4444,
};
const accounts = [account1, account2, account3, account4];
const searchAccount = accounts.findIndex(function (account) {
return account.owner === "Elvis Presley";
});
console.log(searchAccount);

View File

@ -0,0 +1,39 @@
const arr = [1, 2, 3, [4], [5, 6], [7, 8, 9]];
console.log(arr.flat(1));
const deepArr = [1, [2, [3, 4], 5], [6, [7, 8], 9]]; // flat Methode stellt Werte eine Stufe höher um
console.log(deepArr.flat());
const account1 = {
owner: "David Aster",
movements: [200, 450, -400, 3000, -650, -130, 70, 1300],
interestRate: 1.2, // %
pin: 1111,
};
const account2 = {
owner: "Joanne Aster",
movements: [5000, 3400, -150, -790, -3210, -1000, 8500, -30],
interestRate: 1.5,
pin: 2222,
};
const account3 = {
owner: "Nika Aster",
movements: [200, -200, 340, -300, -20, 50, 400, -460],
interestRate: 0.7,
pin: 3333,
};
const account4 = {
owner: "Eva Aster",
movements: [430, 1000, 700, 50, 90],
interestRate: 1,
pin: 4444,
};
const accounts = [account1, account2, account3, account4];
const accountsMovements = accounts.map(acc => acc.movements);
const allMovements = accountsMovements.flat(); // gibt alle Transaktionen aus allen Accounts zurück(extrahiert bestehende Transaktionen, die in den Felder sind)
const overallBalance = allMovements.reduce((acc, cur) => acc + cur); // Berechnung aller Transaktionen

View File

@ -0,0 +1,29 @@
const obst = ["apfel", "erdbeere", "mango", "banane", "orange"];
function checkVerfuegbarkeit(obst, val) {
return obst.some(v => v === val);
}
console.log(checkVerfuegbarkeit(obst, "orange"));
console.log(checkVerfuegbarkeit(obst, "heidelbeere"));
const randomIntNumbers = n => {
let transaktionen = [];
for (let i = 0; i < n; i++) {
const rndNum = Math.random() * 1000;
rndNum > Math.random() * 1000
? transaktionen.push(Math.trunc(rndNum))
: transaktionen.push(-Math.trunc(rndNum));
}
return transaktionen;
};
const deposits = randomIntNumbers(50);
const anyDeposits = deposits.some(deposit => deposit > 0);
console.log(anyDeposits);
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 130, 44].every(isBigEnough); // false, weil da nich alle Werte mehr als 10 sind
[12, 54, 18, 130, 44].every(isBigEnough); // true, weil da alle Werte der Bedienung "element > 10" entsprechen

View File

@ -15,14 +15,14 @@ const account2 = {
};
const account3 = {
owner: "Nika Aster",
owner: "Steven Schmidt",
movements: [200, -200, 340, -300, -20, 50, 400, -460],
interestRate: 0.7,
pin: 3333,
};
const account4 = {
owner: "Eva Aster",
owner: "Elvis Presley",
movements: [430, 1000, 700, 50, 90],
interestRate: 1,
pin: 4444,