/** * probeklausur-2.js * */ import {terminal} from "./dfhi.js"; // Aufgabe 1 function reichweite(beta, v0) { const G = 9.81; return (v0*v0)/G*Math.sin(2 * (beta*Math.PI/180) ); } // Aufgabe 2 function countFrequency(genomeCode) { let count = { length: genomeCode.length, A: 0, C: 0, G: 0, T: 0 } ; for(let code of genomeCode) { count[code] += 1; } return count; } // alternativ kann man auch die Prozent darauf rechnen. Wichtig ist einheitlich halten. function countPercent(frequency) { return { A: frequency['A']/frequency['length'], C: frequency['C']/frequency['length'], G: frequency['G']/frequency['length'], T: frequency['T']/frequency['length'] } } // Aufgabe 3 // 1) let calculateTax = (bill) => { const MWST = 0.19; return Object.assign({withtax: (bill['net'] * (1 + MWST)) }, bill)}; // 2) let pricePerUnit = (bill) => Object.assign({pricePerUnit:bill['withtax']/bill['quatity']}, bill); // 3) let comparePrice = (bill1, bill2) => bill1.pricePerUnit - bill2.pricePerUnit; // Hier ist nur zum Demonstrierenszwech, gehört nicht direkt zur Lösung. // Sie können statt termin.printl auch console.log benutzen um das Objekt zu unter suchen. window.main = function(...argv) { terminal.printl("Sieh Source Code"); terminal.printl("Test Aufgabe 1"); let beta=45, v0 = 100; let r = reichweite(beta, v0); terminal.printl({beta, v0, r}); terminal.printl("Test aufgabe 2"); let code = "ATGACGGATCAGCCGCAAGCGG"; let frequency = countFrequency(code); let percent = countPercent(frequency); terminal.printl({code, frequency, percent}); terminal.printl("Test Aufgabe 3"); let invoice = [ {goods: "Banana", quatity: 2, unit: "kg", net: 2.68 }, {goods: "Mango", quatity: 3, unit: "kg", net: 5.34 }, {goods: "Apple", quatity: 1, unit: "kg", net: 0.65 } ]; let invoiceWithTax = invoice.map(calculateTax); terminal.printl("invoiceWithTax:"); terminal.printl(invoiceWithTax); let invoiceWithTaxAndPricePerUnit = invoiceWithTax.map(pricePerUnit); terminal.printl("invoiceWithTaxAndPricePerUnit"); terminal.printl(invoiceWithTaxAndPricePerUnit); let sortByPrice = invoiceWithTaxAndPricePerUnit.sort(comparePrice); terminal.printl("sortByPrice"); terminal.printl(sortByPrice); let chainedCall = invoice.map(calculateTax).map(pricePerUnit).sort(comparePrice); terminal.printl("chainedCall"); terminal.printl(chainedCall); };