-
Notifications
You must be signed in to change notification settings - Fork 13
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
hauptsächlich obj vs json bis u mit aufgabe 4 #10
Open
marcorensch
wants to merge
6
commits into
ibwgr:master
Choose a base branch
from
marcorensch:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6d6d131
some
marcorensch 293c688
some
marcorensch b87eeda
Bis Aufgabe 4 objects . hs vs json
marcorensch 7fceb57
Merge branch 'ibwgr:master' into master
marcorensch 74a17f4
Bis und mit Aufgabe 5 Obj-js-vs-json
marcorensch c0808be
Merge remote-tracking branch 'origin/master'
marcorensch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// 1 | ||
// a. Was gibt folgender Code aus? | ||
|
||
for (var i = 0; i < 4; i++) { | ||
setTimeout(() => { | ||
console.log(i) | ||
}, 2000) | ||
} | ||
|
||
// b. Wie kann ich das Programm ändern, damit es tut was es tun sollte. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Soll die Quersumme 13 ergeben | ||
const a = [1,34,5, 0, -4] | ||
// let b = a.reduce((a,sum) => sum + a) | ||
// console.log(b) // 40 => Falsch | ||
|
||
|
||
// https://bobbyhadz.com/blog/javascript-split-number-into-array | ||
let b = a.reduce((sum,a) => { | ||
if(a > 0 && a < 10){ | ||
return sum + a | ||
} | ||
if(a >= 10){ | ||
let digits = Array.from(String(a), Number) | ||
return sum + digits.reduce((d,s) => d+s) | ||
} | ||
return sum | ||
}) | ||
console.log(b) | ||
|
||
// Funktional: | ||
function quersumme(arrayOfDigits){ | ||
console.log(arrayOfDigits) | ||
return arrayOfDigits.reduce((sum, n)=>{ | ||
if(n > 0 && n < 10){ | ||
return sum + n | ||
} | ||
if(n >= 10){ | ||
return sum + Array.from(String(n), Number).reduce((s,d) => d+s) | ||
} | ||
return sum | ||
}) | ||
} | ||
console.log(quersumme(a)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 1 | ||
// gegeben | ||
// function add(a, b){ | ||
// return a + b | ||
// } | ||
// | ||
// Erstelle eine Funktion namens aPlusb welche einen Parameter p entgegen nimmt, | ||
// und intern immer add mit a=20 aufruft, b soll mit p belegt werden. | ||
// Gib das Ergebnis der Berechnung zurück. | ||
// Versuche zwei Lösungs-Varianten zu finden (Hint: bind). | ||
|
||
|
||
|
||
// 2 | ||
// Die gegebene Funktion add aus Aufgabe 1 soll geändert werden. | ||
// Neu möchten wir, dass immer alle Argumente geloggt werden (bevor die Berechnung gemacht wird). | ||
// Der Aufrufer kann selbst entscheiden was für einen Logger er verwenden möchte. | ||
// z.B. console.log oder console.warn wären mögliche Logger. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
let zahlen = [5,6,7,8] | ||
|
||
// 1 | ||
{ | ||
// Funktional | ||
function sum(array){ | ||
// Startwert || vorangegangener Wert:sum | ||
// Aktuelle Zahl im Array:val | ||
return array.reduce((sum,val) =>sum + val, 0); | ||
} | ||
console.log(sum(zahlen)) | ||
|
||
// Imperativ | ||
let summe = zahlen.reduce((sum, val) =>sum + val) | ||
console.log(summe) | ||
} | ||
|
||
//2 | ||
{ | ||
//Funktional | ||
function even(array){ | ||
// Current number in iteration:value | ||
return array.map(value => value%2 === 0 ) | ||
} | ||
|
||
console.log(even(zahlen)) | ||
|
||
// Imperativ | ||
// Current number in iteration:v | ||
let isEvenArr = zahlen.map(v => v%2 === 0) | ||
console.log(isEvenArr) | ||
} | ||
|
||
// 3.1 | ||
{ | ||
/** | ||
* | ||
* @param arr Array das gefiltert werden soll | ||
* @param fn Funktion die mitgegeben wird um zu prüfen ob Kriterium erfüllt wird | ||
*/ | ||
|
||
function myFilter(arr,fn){ | ||
let ret = [] | ||
arr.forEach(v =>{ | ||
if(fn(v)) ret.push(v) | ||
}) | ||
return ret | ||
} | ||
|
||
let filtered = myFilter(zahlen,(n)=>n>6) | ||
console.log(filtered) | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// 'use strict' // optional, weil im Browser via <script type="module" ...> geladen | ||
|
||
// import named export | ||
import {Logger} from './logger.module.mjs' | ||
import {PI} from './logger.module.mjs' | ||
// rename import | ||
import {PI as pii} from './logger.module.mjs' | ||
|
||
let l = new Logger(console.log) | ||
l.warn('hi') | ||
l.log('du') | ||
l.log([pii, PI, Logger.PI]) | ||
console.log(document.getElementsByTagName('p')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Modules</title> | ||
<script type="module" src="app.mjs"></script> | ||
</head> | ||
<body> | ||
<p></p> | ||
</body> | ||
</html> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
|
||
// Namespacing | ||
// Datei1 | ||
let ProjectX = ProjectX || {} | ||
ProjectX.TodoList = ProjectX.TodoList || {} | ||
ProjectX.TodoList.items = [ | ||
{ | ||
text: 'Einkaufen', | ||
done: false | ||
} | ||
] | ||
|
||
// Datei2 | ||
let ProjectX = ProjectX || {} | ||
ProjectX.TodoList = ProjectX.TodoList || {} | ||
ProjectX.TodoList.create = function(text){ | ||
this.items.push({ | ||
text, | ||
done: false | ||
}) | ||
} | ||
ProjectX.TodoList.create('Abwaschen') | ||
|
||
// IIFE | ||
// loose module augmentation pattern | ||
let TodoList = (function(modul){ | ||
let items = [] | ||
modul.create = function(text){ | ||
items.push({ text: text, done: false}) | ||
} | ||
modul.getItems = function(){ | ||
return items; | ||
} | ||
return modul | ||
|
||
})(TodoList || {}) | ||
|
||
TodoList.create('Einkaufen') | ||
TodoList |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mit imperativ ist gemeint: keine funktionalen konzepte verwenden. sprich: mit for schleife arbeiten.