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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
11 changes: 8 additions & 3 deletions exercises/001.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Write a function 'transformFirstAndLast' that takes in an array, and returns an
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']
array = ['Queen', 'Elizabeth', 'Of Hearts', 'Beyonce']
Function's return value (output):
{
Queen : 'Beyonce'
Expand All @@ -21,7 +21,12 @@ function transformFirstAndLast(array) {
// your code here
}
*/
// const arr = ['Queen', 'Elizabeth', 'Of Hearts', 'Beyonce']

function transformFirstAndLast(array) {
//your code here
}
let obj = {};
obj[array[0]] = array[array.length - 1];
return obj;
}
// console.log(transformFirstAndLast(arr))
// console.log(arr);
10 changes: 9 additions & 1 deletion exercises/002.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ function getAllKeys(obj) {
}
*/

// const object = {key1: 'value1', key2: 'value2'};

function getAllKeys(obj){
// your code here
const arr = [];
for(let key in obj) {
arr.push(key.toString());
}
return arr;
}

// console.log(getAllKeys(object));
11 changes: 9 additions & 2 deletions exercises/003.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ For instance, if the input had 6 values instead of 4, your code should flexibly
Starter Code:
*/

function fromListToObject(array) {
// your code here
// const arr = [['make', 'Ford'], ['model', 'Mustang'], ['year', 1964]];

function fromListToObject(array) {
const obj = {};
array.forEach(element => {
obj[element[0]] = element[1];
})
return obj;
}

// console.log(fromListToObject(arr));
16 changes: 14 additions & 2 deletions exercises/004.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ Function's return value (output):
Starter Code
*/

// const object = {
// a : 'a',
// number : 11,
// hungry : true,
// grammyWins : 1
// }

function listAllValues(obj) {
// your code here
const arr = [];
for(key in obj) {
arr.push(obj[key]);
}
return arr;
}

}
// console.log(listAllValues(object));
32 changes: 31 additions & 1 deletion exercises/005.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,37 @@ For example, let's say the HR department adds a "tshirtSize" field to each emplo
Starter Code :
*/

// const input = [
// [
// ['firstName', 'Joe'], ['lastName', 'Blow'], ['age', 42], ['role', 'clerk']
// ],
// [
// ['firstName', 'Mary'], ['lastName', 'Jenkins'], ['age', 36], ['role', 'manager']
// ],
// [
// ['firstName', 'Extra'], ['lastName', 'Spicy'], ['age', 234], ['role', 'hard code spoiler']
// ]
// ];

function transformEmployeeData(array) {
// your code here
const output = [];
array.forEach(el => {
output.push(fromListToObject(el));
})
return output;
}

// From previous exercise

function fromListToObject(array) {
const obj = {};
array.forEach(element => {
obj[element[0]] = element[1];
})
return obj;
}

// const output = transformEmployeeData(input);
// console.log(output);


34 changes: 32 additions & 2 deletions exercises/006.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,36 @@ E.g., it should also be able to handle this, or any other object containing simp
Starter Code:
*/

// const input = {
// name: 'Holly',
// age: 35,
// role: 'producer',
// extra: 'Uh Oh'
// }

function convertObjectToList(obj) {
// your code here
}
const output = [];
for(let i = 0; i < getAllKeys(obj).length; i++){
output[i] = [getAllKeys(obj)[i], listAllValues(obj)[i]];
}
return output;
}
// From previous exercises

function listAllValues(obj) {
const arr = [];
for(key in obj) {
arr.push(obj[key]);
}
return arr;
}

function getAllKeys(obj){
const arr = [];
for(let key in obj) {
arr.push(key.toString());
}
return arr;
}

// console.log(convertObjectToList(input));
36 changes: 19 additions & 17 deletions exercises/007.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,26 @@ Starter Code :
*/

var customerData = {
'Joe': {
visits: 1
},
'Carol': {
visits: 2
},
'Howard': {
visits: 3
},
'Carrie': {
visits: 4
}
'Joe': {visits: 1},
'Carol': {visits: 2},
'Howard': {visits: 3},
'Carrie': {visits: 4}
};
// console.log(customerData['Joe'].visits);

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

return greeting;
}
let greeting = '';
for(name in customerData){
if(name === firstName){
if(customerData[name].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!`;
}
return greeting;
}
}
return greeting = `Welcome! Is this your first time?`;
}

// console.log(greetCustomer(""));