Hong-Phuc Bui
2024-10-16 f8613c9ce2bd4b74b11727d2eae204f49151bcba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
 * 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);
};