Skip to content
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

Created HW1 branch #2

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));