hinzugefügt data transform Funktionen (map,filter, reduce), hinzugefügt Berechnung der Transaktionen Mithilfe die reduce Funktion

This commit is contained in:
David 2022-11-07 11:42:40 +01:00
parent 52816cb770
commit 8edb61128b
2 changed files with 36 additions and 1 deletions

View File

@ -60,7 +60,7 @@ console.log(arr);
arr = arr.reduce(function (prev, curr) {
return prev + curr;
});
// Array wird in einen Wert konvertiert
// Array wird in einen numerischen Wert konvertiert
console.log(arr);
const user = "David Steven Schmidt Aster";
@ -88,3 +88,16 @@ const createUsernames = function (accounts) {
createUsernames(accounts);
console.log(accounts);
const movements = [200, 450, -400, 3000, -650, -130, 70, 1300];
// das Expression, das nicht der Bedienung entpricht, wird ins Feld nicht hinzugefügt
const deposits = movements.filter(function (mov) {
return mov > 0; //Transtaktionen, die mehr als 0 sind, werden in das Feld hinzugefügt
});
console.log(`Deposits ${deposits}`);
const withdrawals = movements.filter(function (mov) {
return mov <= 0; //Transtaktionen, die wenig oder gleich 0 sind, werden in das Feld hinzugefügt
});
console.log(`Withdrawals ${withdrawals}`);

View File

@ -0,0 +1,22 @@
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 arrOfTrans = randomIntNumbers(10);
console.log(`Alle Transaktionen: ${arrOfTrans}`);
const saldo = arrOfTrans.reduce(function (accu, cur, index) {
const transaktion = cur > 0 ? "deposit" : "witdrawal";
console.log(
`Konto Status: ${accu}, Transaktion ${index}: ${cur} (${transaktion})`
);
return accu + cur;
});
console.log(`Saldo: ${saldo} EUR`);