Skip to content

Uebungen #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a8efb26
Teil Aufgaben gelöst
cm-clodos Mar 28, 2022
caae48d
Aufgaben Teil1
cm-clodos Apr 1, 2022
ae736be
Bug Quersumme
cm-clodos Apr 1, 2022
bb26d8f
Aufgaben gelöst bis auf Quersumme
cm-clodos Apr 2, 2022
0f387f3
Fibonacci gelöst
cm-clodos Apr 2, 2022
97991c0
Fibonacci gelöst
cm-clodos Apr 2, 2022
2af4662
Aufgaben object fertig
cm-clodos Apr 2, 2022
08b2291
Aufgaben Quersumme gelöst
cm-clodos Apr 3, 2022
4b959a2
Basic Aufgabe gelöst
cm-clodos Apr 3, 2022
e3bec72
zahlenraten hinzugefügt
cm-clodos Apr 8, 2022
ec820e2
Aufgaben closure.js & fn-Objects-callbacks erledigt
cm-clodos Apr 8, 2022
f843327
Aufgaben closure.js & fn-Objects-callbacks erledigt
cm-clodos Apr 9, 2022
2505111
Module und renamed files
cm-clodos Apr 9, 2022
eb6236b
Merge branch 'master' into uebungen
cm-clodos Apr 9, 2022
22a79f5
admin.md gelöst
cm-clodos Apr 10, 2022
c6d2a18
eigene übung zu bind(),apply(), call()
cm-clodos Apr 10, 2022
3d719d4
findAll() erneuert
cm-clodos Apr 11, 2022
2fcd8c9
findAll() erneuert nochmals ;)
cm-clodos Apr 11, 2022
39925cc
eigene Klassen und Module
cm-clodos May 1, 2022
172e6fb
functional uebung
cm-clodos May 6, 2022
af98169
3.1 gelöst
cm-clodos May 9, 2022
8423865
3.2 gelöst
cm-clodos May 9, 2022
8c5ad9b
3.2 gelöst
cm-clodos May 9, 2022
6d4100c
functional-imperativ.md gelöst
cm-clodos May 9, 2022
0e10b42
schleifen-funtional-uebungen.js bis übung 5 gelöst
cm-clodos May 9, 2022
28058ba
schleifen-funtional-uebungen.js bis übung 5 refactor
cm-clodos May 9, 2022
fe9aad0
schleifen-funtional-uebungen.js noch 2 Aufgaben zu lösen
cm-clodos May 10, 2022
211e8d1
object vs JSON aufgabe 1-2
cm-clodos May 15, 2022
d89a4af
object vs JSON aufgabe 3
cm-clodos May 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/destructering.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict'

// swap
// let a = 1 ,b = 2, arr = [a, b];
//let a = 1 ,b = 2, arr = [a, b];


//[b, a] = [a, b]

// [b, a] = [a, b]

// // default values
// let [eins, zwei, drei = 3] = arr
Expand Down
71 changes: 71 additions & 0 deletions src/exercises/MeineLoesung/Object-js-vs-json-uebungen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"use strict"
//1

const users = [
{
name: "Martin",
score: 100
},
{
name: "Sven",
score: 20
},
{
name: "Eva",
score: 33
},
{
name: "Heike",
score: 40
}
]

// sortiert aufsteigend a.score - b.score **** b.score -a.score sortiert absteigend
users.sort((a, b) => {
return a.score - b.score
}).forEach((e) => {
console.log(e)
})

//2
let topScorer = users.sort((a, b) => {
return b.score -a.score
})

let topThree1 = [topScorer[0], topScorer[1], topScorer[2]]
console.log(topThree1)

let topThree2 = topScorer.slice(0, 3)
console.log(topThree2)

//
let topThree3 = topScorer.filter((value,index) => {
return index <= 2
})
console.log(topThree3)


const jsonUsers = JSON.stringify(topThree3)
console.log(jsonUsers)

//3

let userChange = users.map( user => ({
content: user.name,
length: user.name.length

})).sort((a, b) => {
return a.length - b.length
})

console.log(userChange)

//4





//5


37 changes: 37 additions & 0 deletions src/exercises/MeineLoesung/admin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export class Person {
nachname
vorname

constructor(nachname, vorname) {
this.nachname = nachname
this.vorname = vorname
}
}

export class Store {
items = []

constructor(items) {
this.items = items
}

add(item) {
this.items.push(item)
}

remove(item) {
let indexToRemove = this.items.indexOf(item)
this.items.splice(indexToRemove, 1)
}

findAll(matcher) {
const foundItems = []
for (const item of this.items) {
//matcherfunktion = true, dann push item in foundItems Array
if (matcher(item)){
foundItems.push(item)
}
}
return foundItems
}
}
58 changes: 58 additions & 0 deletions src/exercises/MeineLoesung/basicAufgabe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use strict"

// Aufgabe 1.1

function returnName (name){
return "Hallo \<" + name + "\>"
}

console.log(returnName("Claudia"))

//Aufgabe 1.2
function returnNameDefault (name , to = "Welt"){
if (name === undefined){
return "Hallo \<" + to + "\>"
}else {
return "Hallo \<" + name+ "\>"
}

}

console.log(returnNameDefault())
console.log(returnNameDefault("Claudia"))

//Aufgabe 1.3

function returnMoreNameDefault (...name){
if (name.length === 0){
name.push("Welt")
}else{
name.push(name)
}
let nameOutput = name.join(", ")

return "Hallo " + nameOutput
}

console.log(returnMoreNameDefault("Claudia", "Simon", "Marco"))
console.log(returnMoreNameDefault())

//"use strict"
function test1 (){
console.log(this)
}
test1()
let objekt={
name: "Claudia",
say: function (){
console.log(this.name)
}

};
console.log(objekt.name)
let objektName = objekt.say()
console.log(objektName)
console.log(objekt.__proto__)



31 changes: 31 additions & 0 deletions src/exercises/MeineLoesung/classes/Car.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict"

export class Car {
// private #brand
#brand;
color;
fuel;

constructor(brand, color, fuel) {
this.#brand = brand;
this.color = color;
this.fuel = fuel;
this._brand = brand;
}

drive(){
console.log(`Car: ${this.brand} with the color: ${this.color} drives with ${this.fuel} `)
}


get brand() {
return this._brand;
}

set brand(value) {
this._brand = value;
}


}

21 changes: 21 additions & 0 deletions src/exercises/MeineLoesung/classes/RacingCar.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict"
import {Car} from "./Car.mjs";
//

export class RacingCar extends Car {
team;
horsePower;

constructor(brand, color, fuel, team, horsePower) {
super(brand,color,fuel);
this.team = team;
this.horsePower = horsePower;
}

drive(){
console.log(`Racingcar: Team: ${this.team} with the brand: ${this.brand} drives with ${this.horsePower} `)
}



}
16 changes: 16 additions & 0 deletions src/exercises/MeineLoesung/classes/app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Car} from "./Car.mjs";
import {RacingCar} from "./RacingCar.mjs";

let car1 = new Car("VW", "White", "Gas");
let raceCar = new RacingCar("BMW", "Black", "Diesel", "Sauber", 450)

car1.drive()
raceCar.drive()

// Use getter
console.log(car1.brand)
console.log(raceCar.brand)
//use setter
car1.brand = "Smart"
console.log(car1.brand)

22 changes: 22 additions & 0 deletions src/exercises/MeineLoesung/client.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import {Person, Store} from './admin.mjs'

const person1 = new Person("Martinez", "Claudia")
const person2 = new Person("Martinez", "Marco")
const person3 = new Person("Martinez", "Antonio")
const person4 = new Person("Rumhold", "Eva")
const person5 = new Person("Germann", "Simon")
let persons = [person1, person2, person3]

const store = new Store(persons)

store.add(person4)
console.log(persons)

store.remove(person1)
console.log(persons)
console.log("*********************************")

let found = store.findAll((person) => person.nachname === "Martinez")
console.log(found)

28 changes: 28 additions & 0 deletions src/exercises/MeineLoesung/eigeneUebungen/function-methods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// übung für call(), apply() bind()


let bob = function (num, str,x){
console.log('bob', num, str, this, x)

return true
}

let bill = {
name:'Bill Murray',
movie: 'Lost in translation',
myMethod: function (fn){


}
}

//bob(1, 'hi') // bob, 1, hi, this => global Object ( use strict: this => undefined)

//bill.myMethod(bob) // auch wenn myMethod instanz methode ist => ruft inner funktion auf, bei der this => global
//bill.myMethod(bob.call(bill, 10, 'Welt'))// call(thisArgument, parameter1, parameter2 ) output => bob, 10, Welt, {bill}
//bill.myMethod(bob.apply(bill,[20, 'Planet']))// apply(thisArgument, [parameter1, parameter2] output => bob, 20, Planet, {bill}


//bill.myMethod(bob(2, 'blödian')) // nicht gebunden müssen parameter zur laufzeit übergeben werden
let gebundeneFunktion = bob.bind(bill, 30, 'Universum'); // thisContext + Parameter können vor der Ausführung gespeichert werden ( Bind() macht nur KOPIE von Funktion)
gebundeneFunktion("3. parameter x: nachträglich eingefügt => nach bind()")// Muss separat ausgeführt werden
Loading