From 8128f3db7726bc8dfb9ec408685a4bc641bd5d1a Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:54:58 +0100 Subject: [PATCH 01/19] Add function --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index bea6dce..0699719 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,7 @@ // 1. Add function code goes here -exports.add = function add() {}; +exports.add = function add(x, y) { + return x + y +}; // 2. Multiply function code goes here exports.multiply = function multiply() {}; From c37148a8147e610d6ee16721e63a8d2427c3811a Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:55:34 +0100 Subject: [PATCH 02/19] Multiply function --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 0699719..1ed8f87 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,9 @@ exports.add = function add(x, y) { }; // 2. Multiply function code goes here -exports.multiply = function multiply() {}; +exports.multiply = function multiply(x, y) { + return x * y +}; // 3. OddOrEven function code goes here exports.oddOrEven = function oddOrEven() {}; From 2174c934ee28a1aa8debf9bf30c57a5cd59aa2da Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:56:14 +0100 Subject: [PATCH 03/19] OddOrEven function --- src/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 1ed8f87..7788bfa 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,13 @@ exports.multiply = function multiply(x, y) { }; // 3. OddOrEven function code goes here -exports.oddOrEven = function oddOrEven() {}; +exports.oddOrEven = function oddOrEven(x) { + if(x % 2 == 0) { + return ('even') + } else { + return ('odd') + } +}; // 4. Write a function that returns an array that includes number 1 to 100 // Ex: [1,2,3,4, ..., 99, 100] From 3e88224cedfb3aff8979d0e2142eed804a549d2a Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:56:56 +0100 Subject: [PATCH 04/19] ArrayGenerator function --- src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7788bfa..7620741 100644 --- a/src/index.js +++ b/src/index.js @@ -19,7 +19,14 @@ exports.oddOrEven = function oddOrEven(x) { // 4. Write a function that returns an array that includes number 1 to 100 // Ex: [1,2,3,4, ..., 99, 100] -exports.arrayGenerator = function arrayGenerator() {}; +exports.arrayGenerator = function arrayGenerator() { + let i; + let numbers = []; + for(i=1; i<=100; i++) { + numbers.push(i); + } + return(numbers); +}; // 5. Fix this function. We want to see 2 in the console instead of undefined exports.hoisting = function hoisting() { From 164ed320094cb16b416b1a1a9c2bafd3b7f198bd Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:57:24 +0100 Subject: [PATCH 05/19] Hoisting function --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7620741..558ec68 100644 --- a/src/index.js +++ b/src/index.js @@ -30,8 +30,8 @@ exports.arrayGenerator = function arrayGenerator() { // 5. Fix this function. We want to see 2 in the console instead of undefined exports.hoisting = function hoisting() { - console.log(y); // undefined let y = 2; + return (y); }; // 6. Write a function that accepts unlimited amount of numbers as input From fa11753cc1176fe0d7215899efdcd7b843fe3bbd Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:58:04 +0100 Subject: [PATCH 06/19] MinValue function --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 558ec68..4dbcb8c 100644 --- a/src/index.js +++ b/src/index.js @@ -36,7 +36,9 @@ exports.hoisting = function hoisting() { // 6. Write a function that accepts unlimited amount of numbers as input // and return the smallest value -exports.minValue = function minValue() {}; +exports.minValue = function minValue(...numbers) { + return Math.min(...numbers); + }; // 7. Write a function that accepts an array of numbers as input // and return a new array with all numbers doubled From 11b3f5c47e101770e17fc0834a17feeb823195a6 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 15:15:54 +0100 Subject: [PATCH 07/19] Add function - arrow --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index 4dbcb8c..234b178 100644 --- a/src/index.js +++ b/src/index.js @@ -52,3 +52,6 @@ exports.doubleArray = function doubleArray() {}; exports.findStudentName = function findStudentName() {}; // 9. Transform all of the above into arrow functions below here + +// 1. ADD +const add = (x, y) => x + y; \ No newline at end of file From 271e1221f72573acf50eed5978d0f6b48755c8c2 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 15:16:12 +0100 Subject: [PATCH 08/19] Multiply function - arrow --- src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 234b178..1e44ab0 100644 --- a/src/index.js +++ b/src/index.js @@ -54,4 +54,7 @@ exports.findStudentName = function findStudentName() {}; // 9. Transform all of the above into arrow functions below here // 1. ADD -const add = (x, y) => x + y; \ No newline at end of file +const add = (x, y) => x + y; + +// 2. MULTIPLY +const multiply = (x, y) => x * y; \ No newline at end of file From 568cf3fb3984b1149a46075e4d89bdf3bef2c041 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 15:16:34 +0100 Subject: [PATCH 09/19] OddOrEven function - arrow + ternary --- src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 1e44ab0..8640115 100644 --- a/src/index.js +++ b/src/index.js @@ -57,4 +57,7 @@ exports.findStudentName = function findStudentName() {}; const add = (x, y) => x + y; // 2. MULTIPLY -const multiply = (x, y) => x * y; \ No newline at end of file +const multiply = (x, y) => x * y; + +// 3. ODDOREVEN +const oddOrEven = (x) => (x % 2 == 0) ? 'even' : 'odd'; \ No newline at end of file From f30539507917c9b4f3fe8f56a6d66ce999e26a3a Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 15:17:07 +0100 Subject: [PATCH 10/19] Hoisting function - arrow --- src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 8640115..fd22ef9 100644 --- a/src/index.js +++ b/src/index.js @@ -60,4 +60,7 @@ const add = (x, y) => x + y; const multiply = (x, y) => x * y; // 3. ODDOREVEN -const oddOrEven = (x) => (x % 2 == 0) ? 'even' : 'odd'; \ No newline at end of file +const oddOrEven = (x) => (x % 2 == 0) ? 'even' : 'odd'; + +// 5. HOISTING +const hoisting = () => y = 2; \ No newline at end of file From 4466fb14cde46936321de42b50d75557e4465d44 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 15:17:54 +0100 Subject: [PATCH 11/19] MinValue function - arrow --- src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index fd22ef9..f72b63e 100644 --- a/src/index.js +++ b/src/index.js @@ -63,4 +63,7 @@ const multiply = (x, y) => x * y; const oddOrEven = (x) => (x % 2 == 0) ? 'even' : 'odd'; // 5. HOISTING -const hoisting = () => y = 2; \ No newline at end of file +const hoisting = () => y = 2; + +// 6. MINVALUE +const minValue = (...numbers) => Math.min(...numbers); \ No newline at end of file From 4bb275331df642c81a430453a4ea24fc2832f228 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 15:21:51 +0100 Subject: [PATCH 12/19] ArrayGenerator function - arrow --- src/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/index.js b/src/index.js index f72b63e..a96c386 100644 --- a/src/index.js +++ b/src/index.js @@ -62,6 +62,15 @@ const multiply = (x, y) => x * y; // 3. ODDOREVEN const oddOrEven = (x) => (x % 2 == 0) ? 'even' : 'odd'; +// 4. ARRAYGENERATOR +const arrayGenerator = () => { + let numbers = []; + for(i=1; i<=100; i++) { + numbers.push(i); + } + return(numbers); +}; + // 5. HOISTING const hoisting = () => y = 2; From 3be1cf788281f8c35568a16c42f4585180fb8e22 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 15:22:10 +0100 Subject: [PATCH 13/19] Remove unnecessary declaration --- src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js b/src/index.js index a96c386..92ec307 100644 --- a/src/index.js +++ b/src/index.js @@ -20,7 +20,6 @@ exports.oddOrEven = function oddOrEven(x) { // 4. Write a function that returns an array that includes number 1 to 100 // Ex: [1,2,3,4, ..., 99, 100] exports.arrayGenerator = function arrayGenerator() { - let i; let numbers = []; for(i=1; i<=100; i++) { numbers.push(i); From 40d0a541d9c39789628d322ea9c89a9aa48ecd12 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 15:57:09 +0100 Subject: [PATCH 14/19] DoubleArray function --- src/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 92ec307..9d45a30 100644 --- a/src/index.js +++ b/src/index.js @@ -42,7 +42,13 @@ exports.minValue = function minValue(...numbers) { // 7. Write a function that accepts an array of numbers as input // and return a new array with all numbers doubled // Ex: [1,2,3] => [2,4,6] -exports.doubleArray = function doubleArray() {}; +exports.doubleArray = function doubleArray(...x) { + let doubledArray = []; + for(i = 0; i < x.length; i++) { + doubledArray.push(x[i] * 2); + }; + return doubledArray; +}; // 8. We have an array of students object, each object will have a name property // write a function that accepts a student array as first parameter, and a name as second parameter From 540cfdce3922773ba9dddbe9ec6a28bd64864e51 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 16:00:08 +0100 Subject: [PATCH 15/19] DoubleArray function - arrow --- src/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 9d45a30..0af5b89 100644 --- a/src/index.js +++ b/src/index.js @@ -80,4 +80,13 @@ const arrayGenerator = () => { const hoisting = () => y = 2; // 6. MINVALUE -const minValue = (...numbers) => Math.min(...numbers); \ No newline at end of file +const minValue = (...numbers) => Math.min(...numbers); + +// 7. DOUBLEARRAY +const doubleArray = (...x) => { + let doubledArray = []; + for(i = 0; i < x.length; i++) { + doubledArray.push(x[i] * 2); + }; + return doubledArray; +}; \ No newline at end of file From d1cf2df103fbf46436bd6c7e8fc6113655844b1e Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 16:14:36 +0100 Subject: [PATCH 16/19] Fixed input to accept an array --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 0af5b89..c58b2ed 100644 --- a/src/index.js +++ b/src/index.js @@ -42,7 +42,7 @@ exports.minValue = function minValue(...numbers) { // 7. Write a function that accepts an array of numbers as input // and return a new array with all numbers doubled // Ex: [1,2,3] => [2,4,6] -exports.doubleArray = function doubleArray(...x) { +exports.doubleArray = function doubleArray([...x]) { let doubledArray = []; for(i = 0; i < x.length; i++) { doubledArray.push(x[i] * 2); @@ -83,7 +83,7 @@ const hoisting = () => y = 2; const minValue = (...numbers) => Math.min(...numbers); // 7. DOUBLEARRAY -const doubleArray = (...x) => { +const doubleArray = ([...x]) => { let doubledArray = []; for(i = 0; i < x.length; i++) { doubledArray.push(x[i] * 2); From 570a93a212f7c759fbe783b98c41260f529394c8 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 16:45:23 +0100 Subject: [PATCH 17/19] FindStudentName function --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c58b2ed..7091e44 100644 --- a/src/index.js +++ b/src/index.js @@ -54,7 +54,9 @@ exports.doubleArray = function doubleArray([...x]) { // write a function that accepts a student array as first parameter, and a name as second parameter // and return the student with that name // Example of student array: const students = [{ name: 'a' }, { name: 'b' }]; -exports.findStudentName = function findStudentName() {}; +exports.findStudentName = function findStudentName (studentList, name) { + return studentList.filter(student => student.name === name); +}; // 9. Transform all of the above into arrow functions below here From f34c4d961437f801cc114f9c3f35314554d3f853 Mon Sep 17 00:00:00 2001 From: lillapulay <59831508+lillapulay@users.noreply.github.com> Date: Thu, 11 Mar 2021 16:49:07 +0100 Subject: [PATCH 18/19] FindStudentName function - arrow --- src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7091e44..281d061 100644 --- a/src/index.js +++ b/src/index.js @@ -91,4 +91,7 @@ const doubleArray = ([...x]) => { doubledArray.push(x[i] * 2); }; return doubledArray; -}; \ No newline at end of file +}; + +// 8. FINDSTUDENTNAME +const findStudentName = (studentList, name) => studentList.filter(student => student.name === name); \ No newline at end of file From 337f1435c5ecf34b69f6e1c26394186bb50b8e0e Mon Sep 17 00:00:00 2001 From: Lilla Pulay Date: Sun, 14 Mar 2021 13:44:07 +0100 Subject: [PATCH 19/19] Updated to map() function --- src/index.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/index.js b/src/index.js index 281d061..d44eb7a 100644 --- a/src/index.js +++ b/src/index.js @@ -42,12 +42,8 @@ exports.minValue = function minValue(...numbers) { // 7. Write a function that accepts an array of numbers as input // and return a new array with all numbers doubled // Ex: [1,2,3] => [2,4,6] -exports.doubleArray = function doubleArray([...x]) { - let doubledArray = []; - for(i = 0; i < x.length; i++) { - doubledArray.push(x[i] * 2); - }; - return doubledArray; +exports.doubleArray = function doubleArray(input) { + return input.map(x => x * 2); }; // 8. We have an array of students object, each object will have a name property @@ -85,13 +81,7 @@ const hoisting = () => y = 2; const minValue = (...numbers) => Math.min(...numbers); // 7. DOUBLEARRAY -const doubleArray = ([...x]) => { - let doubledArray = []; - for(i = 0; i < x.length; i++) { - doubledArray.push(x[i] * 2); - }; - return doubledArray; -}; +const doubleArray = (input) => input.map(x => x * 2); // 8. FINDSTUDENTNAME -const findStudentName = (studentList, name) => studentList.filter(student => student.name === name); \ No newline at end of file +const findStudentName = (studentList, name) => studentList.filter(student => student.name === name);