diff --git a/HW1/fifth.js b/HW1/fifth.js new file mode 100644 index 0000000..9f23668 --- /dev/null +++ b/HW1/fifth.js @@ -0,0 +1,29 @@ +let inputNumbers = "1 -3 5 7 9 -1"; +const array = inputNumbers.split(" "); + +function findMin(someArray) { + let minValue = Infinity; + for (let i = 0; i < someArray.length; i++){ + if (+someArray[i] < +minValue) { + minValue = someArray[i]; + } + } + + return minValue; +} + +function findMax(someArray) { + let maxValue = -Infinity; + for (let i = 0; i < someArray.length; i++){ + if (+someArray[i] > +maxValue) { + maxValue = someArray[i]; + } + } + + return maxValue; +} + +minV = findMin(array); +maxV = findMax(array); + +console.log(`${minV} ${maxV}`); \ No newline at end of file diff --git a/HW1/first.js b/HW1/first.js new file mode 100644 index 0000000..840f49d --- /dev/null +++ b/HW1/first.js @@ -0,0 +1,12 @@ +const inputNumber = 10; +let answer = 0; + +if (inputNumber > 0){ + for (let i = 1; i < inputNumber; i++){ + if ((i % 3 === 0) || (i % 5 === 0)){ + answer += i; + } + } +} + +console.log(answer); \ No newline at end of file diff --git a/HW1/fourth.js b/HW1/fourth.js new file mode 100644 index 0000000..9e7e953 --- /dev/null +++ b/HW1/fourth.js @@ -0,0 +1,13 @@ +const inputNumber = 143; + +function is_prime(number) { + for (let i = 2; i < number; i++){ + if (number % i === 0){ + return false; + } + } + + return true; +} + +console.log(is_prime(inputNumber)); \ No newline at end of file diff --git a/HW1/second.js b/HW1/second.js new file mode 100644 index 0000000..300833e --- /dev/null +++ b/HW1/second.js @@ -0,0 +1,5 @@ +const diskNumber = 5; + +answer = (2**diskNumber) - 1; + +console.log(answer); \ No newline at end of file diff --git a/HW1/sixth.js b/HW1/sixth.js new file mode 100644 index 0000000..84e68b4 --- /dev/null +++ b/HW1/sixth.js @@ -0,0 +1,48 @@ +const inputNumber = 2474704649; +const array = inputNumber.toString().split(""); +let resultArray = []; +let tempMax; +let realMax; +let result = 0; + +//Finds max value, but lower than max value before +function findMax(someArray) { + let maxValue = -Infinity; + for (let i = 0; i < someArray.length; i++){ + + //Check if tempMax is empty + if (tempMax != undefined){ + if ((someArray[i] > maxValue) && (someArray[i] < tempMax)) { + maxValue = someArray[i]; + } + } + else{ + if (someArray[i] > maxValue) { + maxValue = someArray[i]; + } + } + + } + + return maxValue; +} + +if (inputNumber > 0) { + realMax = tempMax = findMax(array); + + while (resultArray.length !== array.length){ + for (let i = 0; i < array.length; i++){ + if (array[i] === tempMax){ + resultArray.push(tempMax); + } + } + tempMax = findMax(array); + } +} + +//Convert array to number +for (let i = 0; i < resultArray.length; i++){ + result += resultArray[i] * 10**(resultArray.length - i - 1); +} + +console.log(result); \ No newline at end of file diff --git a/HW1/third.js b/HW1/third.js new file mode 100644 index 0000000..fe4d845 --- /dev/null +++ b/HW1/third.js @@ -0,0 +1,17 @@ +const totalVolume = 1071225; + +function findNB(m){ + let i = -1; + for (i = 1; m > 0; i++){ + m -= i**3; + } + if (m != 0){ + i = -1; + return i + } + else { + return i - 1; + } +} + +console.log(findNB(totalVolume)); \ No newline at end of file