-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from JestAK/HW1
Created HW1 branch
- Loading branch information
Showing
6 changed files
with
124 additions
and
0 deletions.
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,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}`); |
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,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); |
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 @@ | ||
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)); |
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,5 @@ | ||
const diskNumber = 5; | ||
|
||
answer = (2**diskNumber) - 1; | ||
|
||
console.log(answer); |
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,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); |
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,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)); |