From 6b179e43dceab11e4e2e04cf36d89c297ded3e34 Mon Sep 17 00:00:00 2001 From: HK Nelson Date: Fri, 21 Jan 2022 22:19:10 -0500 Subject: [PATCH 1/8] complete exercises --- exercises/001.js | 6 +++++- exercises/002.js | 8 ++++++-- exercises/003.js | 10 ++++++++-- exercises/004.js | 7 ++++++- exercises/005.js | 18 +++++++++++++++--- exercises/006.js | 11 ++++++++++- exercises/007.js | 12 +++++++++--- 7 files changed, 59 insertions(+), 13 deletions(-) diff --git a/exercises/001.js b/exercises/001.js index 962fdaa..8514cdb 100644 --- a/exercises/001.js +++ b/exercises/001.js @@ -23,5 +23,9 @@ function transformFirstAndLast(array) { */ function transformFirstAndLast(array) { - //your code here + var returnObj = {}; + + returnObj[array[0]] = array[array.length - 1]; + + return returnObj; } \ No newline at end of file diff --git a/exercises/002.js b/exercises/002.js index 71af29a..27d9cf4 100644 --- a/exercises/002.js +++ b/exercises/002.js @@ -26,5 +26,9 @@ function getAllKeys(obj) { */ function getAllKeys(obj){ - // your code here -} + var returnArr = []; + + for (var property in obj) { returnArr.push(property) }; + + return returnArr; +} \ No newline at end of file diff --git a/exercises/003.js b/exercises/003.js index 8f0a5d4..bf54f4b 100644 --- a/exercises/003.js +++ b/exercises/003.js @@ -20,6 +20,12 @@ Starter Code: */ function fromListToObject(array) { - // your code here + array = array.flat(); + var returnObj = {}; + + for (var i = 0; i < array.length - 1; i += 2) { + returnObj[array[i]] = array[i + 1]; + } -} + return returnObj; +} \ No newline at end of file diff --git a/exercises/004.js b/exercises/004.js index caed05d..1f36757 100644 --- a/exercises/004.js +++ b/exercises/004.js @@ -28,6 +28,11 @@ Starter Code */ function listAllValues(obj) { - // your code here + var returnArr = []; + for (var key in obj) { + returnArr.push(obj[key]); + } + + return returnArr; } \ No newline at end of file diff --git a/exercises/005.js b/exercises/005.js index eeccb70..283ae46 100644 --- a/exercises/005.js +++ b/exercises/005.js @@ -25,6 +25,18 @@ Starter Code : */ function transformEmployeeData(array) { - // your code here - -} + const arrayOfObj = []; + + for (var i = 0; i < array.length; i++) { + var employeeData = array[i]; + var employeeObject = {}; + + for (var j = 0; j < employeeData.length; j++) { + employeeObject[employeeData[j][0]] = employeeData[j][1]; + } + + arrayOfObj.push(employeeObject); + } + + return arrayOfObj; + } \ No newline at end of file diff --git a/exercises/006.js b/exercises/006.js index dca4c27..f11d504 100644 --- a/exercises/006.js +++ b/exercises/006.js @@ -22,5 +22,14 @@ Starter Code: */ function convertObjectToList(obj) { - // your code here + const returnArr = []; + + for (var key in obj) { + const returnNestedArr = []; + + returnNestedArr.push(key, obj[key]); + returnArr.push(returnNestedArr); + } + + return returnArr; } \ No newline at end of file diff --git a/exercises/007.js b/exercises/007.js index 094e8b5..c208840 100644 --- a/exercises/007.js +++ b/exercises/007.js @@ -49,8 +49,14 @@ var customerData = { function greetCustomer(firstName) { var greeting = ''; - // your code here + if (customerData.hasOwnProperty(firstName) && customerData[firstName]['visits'] === 1) { + greeting = `Welcome back, ${firstName}! We're glad you liked us the first time!`; + } else if (customerData.hasOwnProperty(firstName) && customerData[firstName]['visits'] > 1) { + greeting = `Welcome back, ${firstName}! So glad to see you again!`; + } else { + greeting = 'Welcome! Is this your first time?'; + } + return greeting; -} - +} \ No newline at end of file From 68eecb1a64c38d20ece6913cb5dfa061f9939cfb Mon Sep 17 00:00:00 2001 From: HK Nelson <94695428+hkn8@users.noreply.github.com> Date: Fri, 21 Jan 2022 23:19:36 -0500 Subject: [PATCH 2/8] fixes spacing --- exercises/001.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/exercises/001.js b/exercises/001.js index 8514cdb..fc269a3 100644 --- a/exercises/001.js +++ b/exercises/001.js @@ -2,30 +2,30 @@ Write a function 'transformFirstAndLast' that takes in an array, and returns an object with: 1) the first element of the array as the object's key, and 2) the last element of the array as that key's value. + Example input: ['Queen', 'Elizabeth', 'Of Hearts', 'Beyonce'] + Function's return value (output): { Queen : 'Beyonce' } + Do not change the input array. Assume all elements in the input array will be of type 'string'. Note that the input array may have a varying number of elements. Your code should flexibly accommodate that. + E.g. it should handle input like: ['Kevin', 'Bacon', 'Love', 'Hart', 'Costner', 'Spacey'] + Function's return value (output): { Kevin : 'Spacey' } + Starter Code -function transformFirstAndLast(array) { - // your code here -} */ function transformFirstAndLast(array) { - var returnObj = {}; - - returnObj[array[0]] = array[array.length - 1]; - - return returnObj; -} \ No newline at end of file + //your code here + +} From af5fe8e3e1a7124bfa9f278243a151fc1fc8b5a9 Mon Sep 17 00:00:00 2001 From: HK Nelson <94695428+hkn8@users.noreply.github.com> Date: Fri, 21 Jan 2022 23:20:15 -0500 Subject: [PATCH 3/8] fixes spacing and object method to not use --- exercises/002.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/exercises/002.js b/exercises/002.js index 27d9cf4..8f9a4e2 100644 --- a/exercises/002.js +++ b/exercises/002.js @@ -1,15 +1,19 @@ /* Write a function called "getAllKeys" which returns an array of all the input object's keys. + Example input: { name : 'Sam', age : 25, hasPets : true } + Function's return value (output) : ['name', 'age', 'hasPets'] + Do not use "Object.keys" to solve this prompt. Note that your function should be able to handle any object passed in it. + E.g. it should also handle an input like: { a : 'a', @@ -17,18 +21,14 @@ E.g. it should also handle an input like: hungry : true, grammyWins : 1 } + Function's return value (output): ['a', 'number', 'hungry', 'grammyWins'] + Starter Code: -function getAllKeys(obj) { - // your code here -} */ function getAllKeys(obj){ - var returnArr = []; - - for (var property in obj) { returnArr.push(property) }; - - return returnArr; -} \ No newline at end of file + //your code here + +} From fec69d055d67756fd15898eaa8e9f695501e4004 Mon Sep 17 00:00:00 2001 From: HK Nelson <94695428+hkn8@users.noreply.github.com> Date: Fri, 21 Jan 2022 23:20:45 -0500 Subject: [PATCH 4/8] fixes spacing and object method to not use --- exercises/003.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/exercises/003.js b/exercises/003.js index bf54f4b..8f963ee 100644 --- a/exercises/003.js +++ b/exercises/003.js @@ -12,6 +12,7 @@ Function's return value (output): } Do not change the input string. Assume that all elements in the array will be of type 'string'. +Do not use "Object.fromEntries" to solve this prompt. Note that the input may have a different number of elements than the given sample. For instance, if the input had 6 values instead of 4, your code should flexibly accommodate that. @@ -20,12 +21,6 @@ Starter Code: */ function fromListToObject(array) { - array = array.flat(); - var returnObj = {}; + //your code here - for (var i = 0; i < array.length - 1; i += 2) { - returnObj[array[i]] = array[i + 1]; - } - - return returnObj; -} \ No newline at end of file +} From 73af8cc5e39353ab6b5572b343fd1cf3ebc796cb Mon Sep 17 00:00:00 2001 From: HK Nelson <94695428+hkn8@users.noreply.github.com> Date: Fri, 21 Jan 2022 23:21:04 -0500 Subject: [PATCH 5/8] fixes spacing and object method to not use --- exercises/004.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/exercises/004.js b/exercises/004.js index 1f36757..9178298 100644 --- a/exercises/004.js +++ b/exercises/004.js @@ -11,6 +11,7 @@ Example input: Function's return value (output): ['Krysten', 33, false] +Do not use "Object.values" to solve this prompt. Note that the input may have a different number of keys and values than the given sample. E.g. it should also handle an input like: @@ -28,11 +29,6 @@ Starter Code */ function listAllValues(obj) { - var returnArr = []; - - for (var key in obj) { - returnArr.push(obj[key]); - } - - return returnArr; -} \ No newline at end of file + //your code here + +} From 4a0fc30c099a23bc1312be2283e458fa5e959c6f Mon Sep 17 00:00:00 2001 From: HK Nelson <94695428+hkn8@users.noreply.github.com> Date: Fri, 21 Jan 2022 23:21:27 -0500 Subject: [PATCH 6/8] fixes spacing and object method to not use --- exercises/005.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/exercises/005.js b/exercises/005.js index 283ae46..588bd72 100644 --- a/exercises/005.js +++ b/exercises/005.js @@ -17,6 +17,7 @@ Given that input, the return value should look like this: {firstName: 'Mary', lastName: 'Jenkins', age: 36, role: 'manager'} ] +Do not use "Object.fromEntries" to solve this prompt. Note that the input may have a different number of rows or different keys than the given sample. For example, let's say the HR department adds a "tshirtSize" field to each employee record. Your code should flexibly accommodate that. @@ -25,18 +26,6 @@ Starter Code : */ function transformEmployeeData(array) { - const arrayOfObj = []; + //your code here - for (var i = 0; i < array.length; i++) { - var employeeData = array[i]; - var employeeObject = {}; - - for (var j = 0; j < employeeData.length; j++) { - employeeObject[employeeData[j][0]] = employeeData[j][1]; - } - - arrayOfObj.push(employeeObject); - } - - return arrayOfObj; - } \ No newline at end of file +} From 2c9b28bcb34774e536d7c2a3cc97eb7ff7a9a7a4 Mon Sep 17 00:00:00 2001 From: HK Nelson <94695428+hkn8@users.noreply.github.com> Date: Fri, 21 Jan 2022 23:21:42 -0500 Subject: [PATCH 7/8] fixes spacing and object method to not use --- exercises/006.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/exercises/006.js b/exercises/006.js index f11d504..9107457 100644 --- a/exercises/006.js +++ b/exercises/006.js @@ -1,14 +1,17 @@ /* Write a function called "convertObjectToList" which converts an object literal into an array of arrays, like this: + Argument: { name: 'Holly', age: 35, role: 'producer' } + Return value: [['name', 'Holly'], ['age', 35], ['role', 'producer']] +Do not use "Object.entries" to solve this prompt. Note that your function should be able to handle ANY object like this, not just the exact sample provided above. E.g., it should also be able to handle this, or any other object containing simple key-value pairs. @@ -22,14 +25,6 @@ Starter Code: */ function convertObjectToList(obj) { - const returnArr = []; - - for (var key in obj) { - const returnNestedArr = []; - - returnNestedArr.push(key, obj[key]); - returnArr.push(returnNestedArr); - } - - return returnArr; -} \ No newline at end of file + //your code here + +} From e39480dfa26ceb26b6782717747e67b625c07b30 Mon Sep 17 00:00:00 2001 From: HK Nelson <94695428+hkn8@users.noreply.github.com> Date: Fri, 21 Jan 2022 23:24:00 -0500 Subject: [PATCH 8/8] fixes spacing --- exercises/007.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/exercises/007.js b/exercises/007.js index c208840..47b8d2a 100644 --- a/exercises/007.js +++ b/exercises/007.js @@ -24,7 +24,6 @@ Notes: * Your function should not alter the customerData object to update the number of visits. * Do not hardcode to the exact sample data. This is a BAD IDEA: - if (firstName === 'Joe') { // do something } @@ -49,14 +48,7 @@ var customerData = { function greetCustomer(firstName) { var greeting = ''; - - if (customerData.hasOwnProperty(firstName) && customerData[firstName]['visits'] === 1) { - greeting = `Welcome back, ${firstName}! We're glad you liked us the first time!`; - } else if (customerData.hasOwnProperty(firstName) && customerData[firstName]['visits'] > 1) { - greeting = `Welcome back, ${firstName}! So glad to see you again!`; - } else { - greeting = 'Welcome! Is this your first time?'; - } + //your code here return greeting; -} \ No newline at end of file +}