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

Minwook Kang Assignment #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion exercises/part1-fizzbuzz/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ Start code

===================== */


for (let i = 1; i <= 100; i ++){
if (i%3 === 0 && i%5 === 0) {console.log("FizzBuzz");
} else if (i%3 === 0) {console.log("Fizz");
} else if (i%5 === 0) {console.log("Buzz");
} else {console.log(i);}
}


/* =====================
Expand Down
76 changes: 56 additions & 20 deletions exercises/part2-basic-functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,112 @@ in years. (Let's just assume this person was born January 1 at 12:01 AM)
Example: "age(2000) should return 22"
===================== */

let age = (birthYear) => {};
let age = (birthYear) => {
return 2022 - birthYear
};

console.log('age success:', age(1971) === 51);
console.log('age:', age(1991))

/*console.log('age success:', age(1971) === 51);

/* =====================
Instructions: Write a function that adds one to the number provided
Example: "plusOne(2) should return 3"
===================== */

let plusOne = () => {};
let plusOne = (x) => {
return x+1;
};
console.log(plusOne(2))

console.log('plusOne success:', plusOne(99) === 100);
/*console.log('plusOne success:', plusOne(99) === 100);

/* =====================
Instructions: Write a function that multiplies the number provided by three
Example: "timesThree(2) should return 6"
===================== */

let timesThree = () => {};
let timesThree = (x) => {
return x*3;
};
console.log(timesThree(2))

console.log('timesThree success:', timesThree(33) === 99);
/*console.log('timesThree success:', timesThree(33) === 99);

/* =====================
Instructions: Write a function that adds two given numbers
Example: "add(2, 3) should return 5"
===================== */

let add = () => {};
let add = (x, y) => {
return x+y
};
console.log(add(2,3))

console.log('add success:', add(4, 6) === 10);
/*console.log('add success:', add(4, 6) === 10);

/* =====================
Instructions: Write a function that multiplies two given numbers
Example: "multiply(2, 3) should return 6"
===================== */

let multiply = () => {};
let multiply = (x, y) => {
return x*y;
};
console.log(multiply(2,3));

console.log('multiply success:', multiply(4, 6) === 24);
/*console.log('multiply success:', multiply(4, 6) === 24);

/* =====================
Instructions: "Write a function that returns the value of an array at a specified index"
Example: "valueAtIndex(['Mercury', 'Venus', 'Earth', 'Mars'], 2) should return 'Earth'"
===================== */

let valueAtIndex = () => {};

console.log('valueAtIndex success:', valueAtIndex([9, 8, 7, 6, 5], 2) === 7);

let valueAtIndex = (arr, i) => {
return arr[i]
};
console.log(valueAtIndex(['Mercury', 'Venus', 'Earth', 'Mars'], 2))

/* =====================
Instructions: "Write a function that returns the value of an object at a specified key"
Example: "valueAtKey({'name': 'Nathan'}, 'name') should return 'Nathan'"
===================== */

let valueAtKey = () => {};

console.log('valueAtKey success:', valueAtKey({ 'foo': 'bar' }, 'foo') === 'bar');
let valueAtKey = (object, key) => {
return object[key]
};
console.log(valueAtKey({ 'foo': 'bar' }, 'foo'));

/* =====================
Instructions: Write a function that returns true if a number is even.
===================== */

let isEven = () => {};
let isEven = (x) => {
if(x%2 === 0){console.log("true")
} else {
console.log("false")
}
}

console.log('isEven success:', isEven(2) === true && isEven(3) === false);
console.log(isEven(2))
console.log(isEven(3))
/*console.log('isEven success:', isEven(2) === true && isEven(3) === false);

/* =====================
Instructions: Write a function that returns true if a number is odd.
===================== */

let isOdd = () => {};

console.log('isOdd success:', isOdd(4) === false && isOdd(5) === true);
let isOdd = (x) => {
if(x%2 != 0){console.log("true")
} else {
console.log("false")
}
}

console.log(isOdd(2))
console.log(isOdd(3))


/*console.log('isOdd success:', isOdd(4) === false && isOdd(5) === true);
97 changes: 84 additions & 13 deletions exercises/part3-iterators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ Instructions: Write a function which counts the number of times a value occurs i
Example: countItem(['a', 'b', 'a'], 'a') should return 2
===================== */

let countItem = (arr, item) => {};
let countItem = (arr, item) => {
let count = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] === item){
count++;
}
}
return count;
};

console.log('countItem success:', countItem([1, 2, 3, 4, 5, 4, 4], 4) === 3);

Expand All @@ -27,8 +35,23 @@ Instructions: Write a function which takes an array and returns a new array with
original array.
===================== */

let isEven = (n) => {};
let filterEven = (arr) => {};
let isEven = (x) => {
if (x%2 === 0){
return (x%2 === 0);
} else {
return ("NA");
}
};

let filterEven = (arr) => {
let evenArr = [];
for (i = 0; i < arr.length; i++){
if (isEven(arr[i]) === true ){
evenArr.push(arr[i])
}
}
return evenArr
};

console.log('filterEven success:', _(filterEven([1, 2, 3, 4, 5, 4, 4])).isEqual([2, 4, 4, 4]));

Expand All @@ -38,8 +61,23 @@ Instructions: Write a function which takes an array and returns a new array with
function MUST use the isOdd function and MUST NOT change the original array.
===================== */

let isOdd = (n) => {};
let filterOdd = (arr) => {};
let isOdd = (x) => {
if (x%2 != 0){
return (x%2 !=0)
} else {
return ("NA")
}
};

let filterOdd = (arr) => {
let oddArr =[];
for (i=0; i<arr.length; i++){
if (isOdd(arr[i]) === true){
oddArr.push(arr[i]);
}
}
return oddArr
};

console.log('filterOdd success:', _(filterOdd([1, 2, 3, 4, 5, 4, 4])).isEqual([1, 3, 5]));

Expand All @@ -50,8 +88,16 @@ Instructions: Write a function which takes an array and returns a new array with
original array.
===================== */

let plusOne = (n) => {};
let mapIncrement = (arr) => {};
let plusOne = (x) => {
return x+1
};
let mapIncrement = (arr) => {
let plusArr = [];
for (i=0; i<arr.length; i++){
plusArr.push(plusOne(arr[i]))
}
return plusArr
};

console.log('mapIncrement success:', _(mapIncrement([1, 2, 3, 4, 5, 4, 4])).isEqual([2, 3, 4, 5, 6, 5, 5]));

Expand All @@ -62,8 +108,16 @@ Instructions: Write a function which takes an array and returns a new array with
original array.
===================== */

let timesThree = (n) => {};
let mapTriple = (arr) => {};
let timesThree = (x) => {
return x*3
};
let mapTriple = (arr) => {
let tripleArr = [];
for (i=0; i<arr.length; i++){
tripleArr.push(timesThree(arr[i]))
}
return tripleArr
};

console.log('mapTriple success:', _(mapTriple([1, 2, 3, 4, 5, 4, 4])).isEqual([3, 6, 9, 12, 15, 12, 12]));

Expand All @@ -74,8 +128,17 @@ Instructions: Write a function which takes an array and returns the sum of all
array.
===================== */

let add = (n1, n2) => {};
let reduceSum = (arr) => {};
let add = (x, y) => {
return x+y
};

let reduceSum = (arr) => {
let totalSum = 0;
for (i=0; i<arr.length; i++){
totalSum = add(totalSum, arr[i]);
}
return totalSum;
};

console.log('reduceSum success:', reduceSum([1, 2, 3, 4, 5, 4, 4]) === 23);

Expand All @@ -86,7 +149,15 @@ Instructions: Write a function which takes an array and returns the product of
original array.
===================== */

let multiply = (n1, n2) => {};
let reduceProduct = (arr) => {};
let multiply = (x, y) => {
return x*y
};
let reduceProduct = (arr) => {
mtpl = 1;
for (i=0; i<arr.length; i++){
mtpl = multiply(mtpl, arr[i]);
}
return mtpl
};

console.log('reduceProduct success:', reduceProduct([1, 2, 3, 4, 5, 4, 4]) === 1920);
Loading