Skip to content
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
5 changes: 4 additions & 1 deletion exercises/001.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ function transformFirstAndLast(array) {

function transformFirstAndLast(array) {
//your code here
}
object ={};
object[array[0]] = array[array.length - 1];
return object;
}
6 changes: 6 additions & 0 deletions exercises/002.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ function getAllKeys(obj) {

function getAllKeys(obj){
// your code here
var keyArray = [];
for (var item in obj){
keyArray.push(item);
}

return keyArray;
}
8 changes: 6 additions & 2 deletions exercises/003.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ Function's return value (output):

Do not change the input string. Assume that all elements in the array will be of type 'string'.

Note that the input may have a different number of elements than the given sample.
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.

Starter Code:
*/

function fromListToObject(array) {
// your code here

object = {};
array.forEach(function(element){
object[element[0]] = element[1];
});
return object;
}
10 changes: 7 additions & 3 deletions exercises/004.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Example input:
Function's return value (output):
['Krysten', 33, false]

Note that the input may have a different number of keys and values than the given sample.
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:
{
Expand All @@ -29,5 +29,9 @@ Starter Code

function listAllValues(obj) {
// your code here

}
var valueArray = [];
for (var item in obj){
valueArray.push(obj[item]);
}
return valueArray;
}
12 changes: 10 additions & 2 deletions exercises/005.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Given that input, the return value should look like this:
{firstName: 'Mary', lastName: 'Jenkins', age: 36, role: 'manager'}
]

Note that the input may have a different number of rows or different keys than the given sample.
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.

Expand All @@ -26,5 +26,13 @@ Starter Code :

function transformEmployeeData(array) {
// your code here

var objectArray = [];
array.forEach (function(outerArray) {
var obj = {};
outerArray.forEach(function(innerArray) {
obj[innerArray[0]] = innerArray[1];
});
objectArray.push(obj);
});
return objectArray;
}
7 changes: 6 additions & 1 deletion exercises/006.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ Starter Code:

function convertObjectToList(obj) {
// your code here
}
var arrOfArr = [];
for (var x in obj) {
arrOfArr.push([x,obj[x]]);
}
return arrOfArr;
}
16 changes: 12 additions & 4 deletions exercises/007.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Write a function called "greetCustomer".

Given a name, "greetCustomer" returns a greeting based on how many times that customer has visited the restaurant. Please refer to the customerData object.
Given a name, "greetCustomer" returns a greeting based on how many times that customer has visited the restaurant. Please refer to the customerData object.

The greeting should be different, depending on the name on their reservation.

Case 1 - Unknown customer ( Name is not present in customerData ):
Case 1 - Unknown customer ( Name is not present in customerData ):

var output = greetCustomer('Terrance');
console.log(output); // --> 'Welcome! Is this your first time?'
Expand Down Expand Up @@ -49,8 +49,16 @@ var customerData = {

function greetCustomer(firstName) {
var greeting = '';
// your code here

if (customerData[firstName]) {
if (customerData[firstName].visits == 1) {
greeting = "Welcome back, " + firstName + "! We're glad you liked us the first time!";
} else {
greeting = "Welcome back, " + firstName + "! So glad to see you again!";
};
} else {
greeting = "Welcome! Is this your first time?";
};

return greeting;
}