-
Notifications
You must be signed in to change notification settings - Fork 205
feat: Resolve tasks from basic js module #163
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
base: master
Are you sure you want to change the base?
Changes from all commits
e2f4770
4494edc
e614a24
32e62fb
9052adf
c0d7796
b1c11ca
31942e1
aa9c88a
544b74a
aca5834
e271675
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,46 @@ | ||
| const a = '4.2'; | ||
| const b = 9; | ||
| let a = '4.2'; | ||
| let b = 9; | ||
|
|
||
| console.log(a, b); | ||
| console.log(typeof a, typeof b); | ||
|
|
||
| const concat = a + b; | ||
| // console.log('Wynik konkatenacji:', concat); | ||
|
|
||
| a = parseFloat(a); | ||
|
|
||
| const add = a + b; | ||
| // console.log('Wynik dodawania:', add); | ||
|
|
||
| const substract = a - b; | ||
| // console.log('Wynik odejmowania:', substract); | ||
|
|
||
| const multipli = a * b; | ||
| // console.log('Wynik mnozenia:', multipli); | ||
|
|
||
| const divide = a / b; | ||
| // console.log('Wynik dzielenia:', divide); | ||
|
|
||
| const modulo = a % b; | ||
| // console.log('wynik reszty z dzielenia:', modulo); | ||
|
|
||
| const inc = ++a; | ||
| // console.log('Wynik inkrementacji:', inc); | ||
|
|
||
| const dec = --b; | ||
| // console.log('Wynik dekremenmtacji:', dec); | ||
|
|
||
| const arr = [concat, add, substract, multipli, divide, modulo, inc, dec]; | ||
|
|
||
| const isBigger = []; | ||
| const isSmaller = []; | ||
|
|
||
| const checkResult = arr.map((item) => { | ||
| if (item > 20) { | ||
| isBigger.push(item); | ||
| } else if (item < 20) { | ||
| isSmaller.push(item); | ||
| } | ||
| }); | ||
|
|
||
| console.log('Wyniki działan większy niz 20', isBigger); | ||
| console.log('Wynik dzialan mniejszy niz 20', isSmaller); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="pl"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
| <title>devmentor.pl - JS BASICS - #01</title> | ||
| </head> | ||
| <body> | ||
|
|
||
| </body> | ||
| </html> | ||
| </head> | ||
| <body> | ||
| <script src="./assets/js/app.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,34 @@ | ||
|
|
||
| /* rozwiązanie z pętlą for */ | ||
| const x = 4; | ||
| // const x = prompt('Podaj liczbę!'); | ||
|
|
||
| // for (let i = 1; i <= 9; i++) { | ||
| // const result = x * i; | ||
|
|
||
| // if (x > 0 && x < 10) { | ||
| // console.log(`${x} x ${i} = ${result}`); | ||
| // } else { | ||
| // console.log('Liczba nie mieści się w przedziale od 1 do 9'); | ||
| // } | ||
| // } | ||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
|
|
||
| let a = 3; //podstawa | ||
| let n = 4; //wykładnik | ||
|
|
||
| let counter = 0; | ||
| let result = 1; | ||
| let displayString = ''; | ||
|
|
||
| while (counter < n) { | ||
| counter++; | ||
| result = result * a; | ||
|
|
||
| if (counter === 1) { | ||
| displayString = `${a}`; | ||
| } else { | ||
| displayString = `${displayString} * ${a}`; | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
| console.log(`${displayString} = ${result}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="pl"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
| <title>devmentor.pl - JS BASICS - #02</title> | ||
| </head> | ||
| <body> | ||
|
|
||
| </body> | ||
| </html> | ||
| </head> | ||
| <body> | ||
| <script src="./app.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,52 @@ | ||
| const min = 1; | ||
| const max = 100; | ||
|
|
||
| const a = randomNumber(min, max); | ||
| const b = randomNumber(min, max); | ||
| const c = randomNumber(min, max); | ||
| let a = randomNumber(min, max); | ||
| let b = randomNumber(min, max); | ||
| let c = randomNumber(min, max); | ||
|
|
||
| console.log(a, b, c); | ||
| function randomNumber(min, max) { | ||
| return Math.round(Math.random() * (max - min) + min); | ||
| } | ||
|
|
||
| const getSum = (a, b, c) => { | ||
| a = parseInt(a); | ||
| b = parseInt(b); | ||
| c = parseInt(c); | ||
|
|
||
| const arr = [a, b, c]; | ||
|
|
||
| const arrSort = arr.sort(); | ||
| const twoBiggest = arrSort.slice(1); | ||
|
|
||
| const initVal = 0; | ||
| const sumWithInitVal = twoBiggest.reduce((acc, curr) => acc + curr, initVal); | ||
|
|
||
| return sumWithInitVal; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| }; | ||
|
|
||
| const isEven = function (sum) { | ||
| if (typeof sum === typeof number) { | ||
| return null; | ||
| } else if (sum % 2 === 0) { | ||
| return true; | ||
| } | ||
|
|
||
| function randomNumber(min, max) { | ||
| return Math.round((Math.random() * (max - min)) + min); | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| const showInfo = (num, bool) => { | ||
| const messages = { | ||
| null: `Podany arguments ${num} nie jest liczbą`, | ||
| true: `Podany arguments ${num} jest parzysty`, | ||
| false: `Podany arguments ${num} jest nieparzysty`, | ||
| }; | ||
|
|
||
| const randomBool = messages[bool]; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Teraz już nie potrzebujemy
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O, wow :o
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :) |
||
|
|
||
| return randomBool; | ||
| }; | ||
|
|
||
| const sum = getSum(a, b, c); | ||
| const even = isEven(sum); | ||
| const show = showInfo(sum, even); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // 1. | ||
|
|
||
| const createArray = (a, b) => { | ||
| const emptyArr = []; | ||
|
|
||
| for (let i = 0; i < 20; i++) { | ||
| let randomNumbers = Math.round(Math.random() * (b - a) + a); | ||
| emptyArr.push(randomNumbers); | ||
| } | ||
| return emptyArr; | ||
| }; | ||
|
|
||
| const arr = createArray(1, 100); | ||
| console.log('Tworzymy tablice:', arr); | ||
|
|
||
| // 2. | ||
|
|
||
| const getLargest = function (arrToSort) { | ||
| const sortArr = arrToSort.sort(function (a, b) { | ||
| return b - a; | ||
| }); | ||
|
|
||
| const theBiggestNumbers = sortArr.slice(-20, 10); | ||
| return theBiggestNumbers; | ||
| }; | ||
|
|
||
| const largest = getLargest(arr); | ||
| console.log('Wybieramy 10 największych liczb z posortowanej malejąco tablicy:', largest); | ||
|
|
||
| // 3. | ||
| const getAvg = (arr) => { | ||
| const initValue = 0; | ||
| const sumWithInitValue = arr.reduce((acc, currValue) => acc + currValue, initValue); | ||
|
|
||
| const arithmeticAvg = sumWithInitValue / arr.length; | ||
|
|
||
| return arithmeticAvg; | ||
| }; | ||
|
|
||
| const avg = getAvg([1, 2, 3, 4, 5]); | ||
| console.log('Średnia arytmetyczna tablicy:', avg); | ||
|
|
||
| 4; | ||
|
|
||
| const getArr = (a, b) => { | ||
| const emptyArray = []; | ||
|
|
||
| for (let i = 0; i < 20; i++) { | ||
| let randomNum = Math.round(Math.random() * (b - a) + a); | ||
| emptyArray.push(randomNum); | ||
| } | ||
|
|
||
| return emptyArray; | ||
| }; | ||
|
|
||
| const newArr = getArr(10, 200); | ||
| console.log('Nowa tablica:', newArr); | ||
|
|
||
| const getTenBiggest = (sortNumbers) => { | ||
| const sortArr = sortNumbers.sort(function (a, b) { | ||
| return b - a; | ||
| }); | ||
|
|
||
| const getBiggestTen = sortArr.slice(-20, 10); | ||
| console.log(getBiggestTen); | ||
|
|
||
| initValue = 0; | ||
| const sumBiggestTen = getBiggestTen.reduce((acc, curr) => acc + curr, initValue); | ||
| console.log(sumBiggestTen); | ||
| const avgBiggestTen = sumBiggestTen / getBiggestTen.length; | ||
| console.log(avgBiggestTen); | ||
|
|
||
| return avgBiggestTen; | ||
| }; | ||
|
|
||
| const biggestTen = getTenBiggest(newArr); | ||
| console.log('Średnia arytmetyczna 10 największych liczb:', biggestTen); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| function Student(firstName, lastName) { | ||
| this.firstName = firstName; | ||
| this.lastName = lastName; | ||
| this.grades = {}; | ||
| } | ||
|
|
||
| Student.prototype.addGrade = function (subjectName, grade) { | ||
| const subject = subjectName; | ||
| const grades = this.grades[subject]; | ||
|
|
||
| if (typeof this.grades[subject] === 'undefined') { | ||
| this.grades[subject] = []; | ||
| } | ||
| this.grades[subject].push(grade); | ||
| }; | ||
|
|
||
| const getAvgCalc = function (gradesArray) { | ||
| const initVal = 0; | ||
| const sumWithInit = gradesArray.reduce((acc, curr) => acc + curr, initVal); | ||
| const avgCalc = sumWithInit / gradesArray.length; | ||
|
|
||
| return avgCalc; | ||
| }; | ||
|
|
||
| Student.prototype.getAverageGrade = function (gradeKey) { | ||
| const subject = gradeKey; | ||
| const grades = this.grades[subject]; | ||
|
|
||
| const gradesVal = Object.values(this.grades); | ||
| const allGrades = []; | ||
|
|
||
| for (let i = 0; i < gradesVal.length; i++) { | ||
| let grade = gradesVal[i]; | ||
| for (let j = 0; j < grade.length; j++) { | ||
| allGrades.push(grade[j]); | ||
| } | ||
| } | ||
|
|
||
| if (subject) { | ||
| return grades; | ||
| } else { | ||
| return allGrades; | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| }; | ||
|
|
||
| const student = new Student('Jan', 'Kowalski'); | ||
|
|
||
| student.addGrade('maths', 4); | ||
| student.addGrade('maths', 6); | ||
| student.addGrade('english', 3); | ||
| // const avgMath = student.getAverageGrade('maths'); | ||
| const avg = student.getAverageGrade(); | ||
| const weird = getAvgCalc(avg); | ||
|
|
||
| console.log(student); | ||
| // console.log(avgMath); | ||
| console.log(avg); | ||
| console.log(weird); | ||
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.
👍