Skip to content

Commit

Permalink
Merge pull request #2 from JestAK/HW1
Browse files Browse the repository at this point in the history
Created HW1 branch
  • Loading branch information
JestAK authored Nov 7, 2023
2 parents 7a09ee8 + 343d133 commit 784a244
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
29 changes: 29 additions & 0 deletions HW1/fifth.js
Original file line number Diff line number Diff line change
@@ -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}`);
12 changes: 12 additions & 0 deletions HW1/first.js
Original file line number Diff line number Diff line change
@@ -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);
13 changes: 13 additions & 0 deletions HW1/fourth.js
Original file line number Diff line number Diff line change
@@ -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));
5 changes: 5 additions & 0 deletions HW1/second.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const diskNumber = 5;

answer = (2**diskNumber) - 1;

console.log(answer);
48 changes: 48 additions & 0 deletions HW1/sixth.js
Original file line number Diff line number Diff line change
@@ -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);
17 changes: 17 additions & 0 deletions HW1/third.js
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit 784a244

Please sign in to comment.