Skip to content

Commit

Permalink
Week 3 challenge. finish
Browse files Browse the repository at this point in the history
  • Loading branch information
0bubbles0 committed Jul 8, 2021
1 parent 309c72a commit 402b74b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion week-01-02/javascript-practice/execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
- yield is like return, can be used repeatedly (function running halts temporarily)
- can for-of over it, make `Array.from(numbers(1, 2))`
- Computed Properties:
- **Computed Properties**:
- Create key → `{[x]: 5}`
- `[‘Be’ + ‘tty’]`
```javascript
Expand Down
70 changes: 70 additions & 0 deletions week-03/challenges/kata-Over18.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* Club Bouncer
Write a function that
- looks at a queue
- returns a guest list
- with the full names
- of all people aged 18+
- **Bonus**: last names in alphabetical order
Example guest list:
['Austen, Jane', 'Potter, Harry']
*/

const queue = [
{ firstName: "Harry", lastName: "Baker", age: 15 },
{ firstName: "Emma", lastName: "Smith", age: 20 },
{ firstName: "Tom", lastName: "Smith", age: 18 },
{ firstName: "Jane", lastName: "Austen", age: 17 },
{ firstName: "Mary", lastName: "Shelley", age: 4 },
{ firstName: "Mary", lastName: "Shelley", age: 4 },
{ firstName: "Charles", lastName: "Dickens", age: 50 },
]

//console.log(queue[0].age); //15

function over18(arr) {
// console.log(arr[0].age);
return arr.filter(item => item.age >= 18);
}
//console.log(over18(queue));

function alphabeter(a, b) {
if (a.lastName > b.lastName) {
return 1;
} else if ((a.lastName === b.lastName) && (a.firstName > b.firstName)) {
return 1;
}
return -1;
}

function guestLister(arr) {
// console.log(arr[0].firstName);
return arr
.filter(item => item.age >= 18)
.sort((a, b) => alphabeter(a, b))
.map(item => `${item.lastName}, ${item.firstName}`);
}

function guestLister1(arr) {
// console.log(arr[0].firstName);
let overAge = over18(arr);
let sorted = overAge.sort((a, b) => {
return (a.lastName > b.lastName) ? 1
: ((a.lastName === b.lastName) && (a.firstName > b.firstName)) ? 1
: -1;
if (a.lastName > b.lastName) {
return 1;
} else if (a.lastName === b.lastName) {
return a.firstName > b.firstName ? 1 : -1;
}
return -1;
});
console.log(sorted);
let guestList = sorted.map(item => `${item.lastName}, ${item.firstName}`);
return guestList;
}

console.log(guestLister(queue));
console.log("Should be ",)

0 comments on commit 402b74b

Please sign in to comment.