diff --git a/solutions/day-01/level1.js b/solutions/day-01/level1.js
index 4822ff0..966f32a 100644
--- a/solutions/day-01/level1.js
+++ b/solutions/day-01/level1.js
@@ -1,22 +1,34 @@
"use strict";
class Animal {
constructor(name, age, color, legs) {
- this.name = name;
- this.age = age;
- this.color = color;
- this.legs = legs;
+ this._name = name;
+ this._age = age;
+ this._color = color;
+ this._legs = legs;
}
- GetName() {
- return this.name;
+ get name() {
+ return this._name;
}
- GetAge() {
- return this.age;
+ set name(value) {
+ this._name = value;
}
- GetColor() {
- return this.color;
+ get age() {
+ return this._age;
}
- GetLegs() {
- return this.legs;
+ set age(value) {
+ this._age = value;
+ }
+ get color() {
+ return this._color;
+ }
+ set color(value) {
+ this._color = value;
+ }
+ get legs() {
+ return this._legs;
+ }
+ set legs(value) {
+ this._legs = value;
}
}
class Dog extends Animal {
@@ -24,12 +36,12 @@ class Dog extends Animal {
super(name, age, color, 4);
this.breed = breed;
}
- GetBreed() {
- return this.breed;
- }
- Bark() {
+ bark() {
console.log("woof");
}
}
const john = new Dog('john', 10, "blue", "rotweiler");
-john.Bark();
+var dog = new Dog('dog', 10, "green", "hi");
+dog.name = 'may';
+console.log(dog.name);
+john.bark();
diff --git a/solutions/day-01/level1.ts b/solutions/day-01/level1.ts
index 026a2fe..6db2499 100644
--- a/solutions/day-01/level1.ts
+++ b/solutions/day-01/level1.ts
@@ -1,27 +1,42 @@
class Animal {
- name: string;
- age: number;
- color: string;
- legs: number;
constructor(name: string, age: number, color: string, legs: number) {
- this.name = name;
- this.age = age;
- this.color = color;
- this.legs = legs;
+ this._name = name;
+ this._age = age;
+ this._color = color;
+ this._legs = legs;
}
- GetName() : string {
- return this.name;
+ private _name: string;
+ public get name(): string {
+ return this._name;
}
- GetAge() : number {
- return this.age;
+ public set name(value: string) {
+ this._name = value;
}
- GetColor() : string {
- return this.color;
+
+ private _age: number;
+ public get age(): number {
+ return this._age;
+ }
+ public set age(value: number) {
+ this._age = value;
+ }
+
+ private _color: string;
+ public get color(): string {
+ return this._color;
+ }
+ public set color(value: string) {
+ this._color = value;
}
- GetLegs() : number {
- return this.legs;
+
+ private _legs: number;
+ public get legs(): number {
+ return this._legs;
+ }
+ public set legs(value: number) {
+ this._legs = value;
}
}
@@ -31,14 +46,16 @@ class Dog extends Animal {
super(name, age, color, 4);
this.breed = breed;
}
- GetBreed() {
- return this.breed;
- }
- Bark() {
+ bark() {
console.log("woof");
}
}
const john = new Dog('john', 10, "blue", "rotweiler");
+var dog = new Dog('dog', 10, "green", "hi");
+
+dog.name = 'may';
+
+console.log(dog.name);
-john.Bark();
\ No newline at end of file
+john.bark();
\ No newline at end of file
diff --git a/solutions/day-01/level2.html b/solutions/day-01/level2.html
new file mode 100644
index 0000000..3bd4a4c
--- /dev/null
+++ b/solutions/day-01/level2.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+ Document
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/solutions/day-01/level2.js b/solutions/day-01/level2.js
new file mode 100644
index 0000000..e2faa51
--- /dev/null
+++ b/solutions/day-01/level2.js
@@ -0,0 +1,25 @@
+"use strict";
+class Car {
+ constructor(name, age, color, wheels) {
+ this._name = name;
+ this._age = age;
+ this._color = color;
+ this._wheels = wheels;
+ }
+ makeSound() {
+ console.log("wroom");
+ }
+}
+class Mazda extends Car {
+ constructor(name, age, color, breed) {
+ super(name, age, color, 4);
+ this._breed = breed;
+ }
+ makeSound() {
+ console.log("brap brap");
+ }
+}
+const jim = new Mazda('john', 10, "blue", "rotweiler");
+const jay = new Car('jay', 10, "green", 4);
+jim.makeSound();
+jay.makeSound();
diff --git a/solutions/day-01/level2.ts b/solutions/day-01/level2.ts
new file mode 100644
index 0000000..fa1624c
--- /dev/null
+++ b/solutions/day-01/level2.ts
@@ -0,0 +1,33 @@
+
+class Car {
+ _name: string;
+ _age: number;
+ _color: string;
+ _wheels: number;
+ constructor(name: string, age: number, color: string, wheels: number) {
+ this._name = name;
+ this._age = age;
+ this._color = color;
+ this._wheels = wheels;
+ }
+ makeSound(): void {
+ console.log("wroom")
+ }
+}
+
+class Mazda extends Car {
+ _breed: string;
+ constructor(name: string, age: number, color: string, breed: string) {
+ super(name, age, color, 4);
+ this._breed = breed;
+ }
+ makeSound(): void {
+ console.log("brap brap")
+ }
+}
+
+const jim = new Mazda('john', 10, "blue", "rotweiler");
+const jay = new Car('jay', 10, "green", 4);
+
+jim.makeSound();
+jay.makeSound();
\ No newline at end of file
diff --git a/solutions/day-01/level3.html b/solutions/day-01/level3.html
new file mode 100644
index 0000000..1c6a56b
--- /dev/null
+++ b/solutions/day-01/level3.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+ Document
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/solutions/day-01/level3.js b/solutions/day-01/level3.js
new file mode 100644
index 0000000..b924507
--- /dev/null
+++ b/solutions/day-01/level3.js
@@ -0,0 +1,126 @@
+"use strict";
+class Statistics {
+ constructor(ages) {
+ this._ages = ages;
+ }
+ count() {
+ return this._ages.length;
+ }
+ sum() {
+ var sum = 0;
+ for (var i = 0; i < this._ages.length; i++) {
+ sum += this._ages[i];
+ }
+ return sum;
+ }
+ min() {
+ var min = this._ages[0];
+ for (var i = 1; i < this._ages.length; i++) {
+ if (min > this._ages[i]) {
+ min = this._ages[i];
+ }
+ }
+ return min;
+ }
+ max() {
+ var max = this._ages[0];
+ for (var i = 1; i < this._ages.length; i++) {
+ if (max < this._ages[i]) {
+ max = this._ages[i];
+ }
+ }
+ return max;
+ }
+ range() {
+ const max = this.max();
+ const min = this.min();
+ return max - min;
+ }
+ mean() {
+ return Math.round(this.sum() / this.count());
+ }
+ median() {
+ var sortedArray = this._ages.sort();
+ // console.log(sortedArray);
+ const count = this._ages.length;
+ if (count % 2 == 0) {
+ //paaris
+ return (Math.floor(sortedArray[count / 2]) + Math.round(sortedArray[count / 2])) / 2;
+ }
+ else {
+ //paaritu
+ return sortedArray[Math.round(count / 2) - 1];
+ }
+ }
+ mode() {
+ var sortedArray = this._ages.sort();
+ var hetkeArv = sortedArray[0];
+ var parimArv = sortedArray[0];
+ var parimStreak = 1;
+ var hetkeStreak = 1;
+ for (var i = 1; i < this._ages.length; i++) {
+ if (sortedArray[i] == hetkeArv) {
+ // parimStreak += 1;
+ hetkeStreak += 1;
+ // console.log(hetkeStreak)
+ if (hetkeStreak > parimStreak) {
+ parimArv = hetkeArv;
+ parimStreak = hetkeStreak;
+ }
+ }
+ else {
+ hetkeStreak = 1;
+ }
+ hetkeArv = sortedArray[i];
+ }
+ return { 'mode': parimArv, 'count': parimStreak };
+ }
+ arvuKauguseRuutMeanistSumma() {
+ const mean = this.mean();
+ const count = this.count();
+ var igaArvuKauguseRuutMeanist = [];
+ for (var i = 0; i < count; i++) {
+ const arv = Math.abs(mean - this._ages[i]);
+ igaArvuKauguseRuutMeanist.push(Math.pow(arv, 2));
+ }
+ // console.log(igaArvuKauguseRuutMeanist)
+ var sum = 0.0;
+ for (var i = 0; i < count; i++) {
+ sum += igaArvuKauguseRuutMeanist[i];
+ }
+ return sum;
+ }
+ std() {
+ // const mean = this.mean();
+ const count = this.count();
+ // var igaArvuKauguseRuutMeanist = [];
+ // for (var i = 0; i < count; i++) {
+ // const arv = Math.abs(mean - this._ages[i]);
+ // igaArvuKauguseRuutMeanist.push(Math.pow(arv, 2));
+ // }
+ // console.log(igaArvuKauguseRuutMeanist)
+ // var sum: number = 0.0;
+ // for (var i = 0; i < count; i++) {
+ // sum += igaArvuKauguseRuutMeanist[i];
+ // }
+ return Math.sqrt(this.var());
+ }
+ var() {
+ const count = this.count();
+ return this.arvuKauguseRuutMeanistSumma() / count;
+ }
+}
+const ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26];
+const statistics = new Statistics(ages);
+console.log('Count:', statistics.count()); // 25
+console.log('Sum: ', statistics.sum()); // 744
+console.log('Min: ', statistics.min()); // 24
+console.log('Max: ', statistics.max()); // 38
+console.log('Range: ', statistics.range()); // 14
+console.log('Mean: ', statistics.mean()); // 30
+console.log('Median: ', statistics.median()); // 29
+console.log('Mode: ', statistics.mode()); // {'mode': 26, 'count': 5}
+// console.log('Variance: ',statistics.var()) // 17.5
+console.log('Standard Deviation: ', statistics.std()); // 4.2
+console.log('Variance: ', statistics.var()); // 17.5
+console.log('Frequency Distribution: ', statistics.freqDist()); // [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
diff --git a/solutions/day-01/level3.ts b/solutions/day-01/level3.ts
new file mode 100644
index 0000000..b264af9
--- /dev/null
+++ b/solutions/day-01/level3.ts
@@ -0,0 +1,140 @@
+class Statistics {
+ private _ages: number[];
+ constructor(ages: number[]) {
+ this._ages = ages;
+ }
+
+ public count() : number{
+ return this._ages.length;
+ }
+
+ public sum() : number {
+ var sum = 0;
+ for (var i = 0; i < this._ages.length; i++) {
+ sum += this._ages[i];
+ }
+ return sum;
+ }
+
+ public min() : number {
+ var min = this._ages[0];
+ for (var i = 1; i < this._ages.length; i++) {
+ if (min > this._ages[i]){
+ min = this._ages[i];
+ }
+ }
+ return min;
+ }
+
+ public max() : number {
+ var max = this._ages[0];
+ for (var i = 1; i < this._ages.length; i++) {
+ if (max < this._ages[i]){
+ max = this._ages[i];
+ }
+ }
+ return max;
+ }
+
+ public range(): number {
+ const max = this.max();
+ const min = this.min();
+ return max - min;
+ }
+
+ public mean(): number {
+ return Math.round(this.sum()/this.count());
+ }
+
+ public median(): number {
+ var sortedArray = this._ages.sort();
+ // console.log(sortedArray);
+ const count = this._ages.length;
+ if (count % 2 == 0) {
+ //paaris
+ return (Math.floor(sortedArray[count/2]) + Math.round(sortedArray[count/2])) / 2;
+ } else {
+ //paaritu
+ return sortedArray[Math.round(count/2) - 1];
+ }
+ }
+
+ public mode() {
+ var sortedArray = this._ages.sort();
+ var hetkeArv = sortedArray[0];
+ var parimArv = sortedArray[0];
+ var parimStreak = 1;
+ var hetkeStreak = 1;
+ for (var i = 1; i < this._ages.length; i++) {
+ if (sortedArray[i] == hetkeArv) {
+ // parimStreak += 1;
+ hetkeStreak += 1;
+ // console.log(hetkeStreak)
+ if (hetkeStreak > parimStreak) {
+ parimArv = hetkeArv;
+ parimStreak = hetkeStreak;
+ }
+ } else {
+ hetkeStreak = 1;
+ }
+ hetkeArv = sortedArray[i];
+ }
+ return {'mode': parimArv, 'count': parimStreak};
+ }
+
+ public arvuKauguseRuutMeanistSumma(): number {
+ const mean = this.mean();
+ const count = this.count();
+ var igaArvuKauguseRuutMeanist = [];
+ for (var i = 0; i < count; i++) {
+ const arv = Math.abs(mean - this._ages[i]);
+ igaArvuKauguseRuutMeanist.push(Math.pow(arv, 2));
+ }
+ // console.log(igaArvuKauguseRuutMeanist)
+ var sum: number = 0.0;
+ for (var i = 0; i < count; i++) {
+ sum += igaArvuKauguseRuutMeanist[i];
+ }
+
+ return sum;
+ }
+
+ public std(): number {
+ // const mean = this.mean();
+ const count = this.count();
+ // var igaArvuKauguseRuutMeanist = [];
+ // for (var i = 0; i < count; i++) {
+ // const arv = Math.abs(mean - this._ages[i]);
+ // igaArvuKauguseRuutMeanist.push(Math.pow(arv, 2));
+ // }
+ // console.log(igaArvuKauguseRuutMeanist)
+ // var sum: number = 0.0;
+ // for (var i = 0; i < count; i++) {
+ // sum += igaArvuKauguseRuutMeanist[i];
+ // }
+
+ return Math.sqrt(this.var());
+ }
+
+ public var(): number {
+ const count = this.count();
+ return this.arvuKauguseRuutMeanistSumma()/count;
+ }
+}
+
+const ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26]
+
+const statistics = new Statistics(ages);
+
+console.log('Count:', statistics.count()) // 25
+console.log('Sum: ', statistics.sum()) // 744
+console.log('Min: ', statistics.min()) // 24
+console.log('Max: ', statistics.max()) // 38
+console.log('Range: ', statistics.range()) // 14
+console.log('Mean: ', statistics.mean()) // 30
+console.log('Median: ',statistics.median()) // 29
+console.log('Mode: ', statistics.mode()) // {'mode': 26, 'count': 5}
+// console.log('Variance: ',statistics.var()) // 17.5
+console.log('Standard Deviation: ', statistics.std()) // 4.2
+console.log('Variance: ',statistics.var()) // 17.5
+console.log('Frequency Distribution: ',statistics.freqDist()) // [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
\ No newline at end of file