10000 find the oldest complete · cqkh42/javascript-exercises@43ecce4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 43ecce4

Browse files
committed
find the oldest complete
1 parent 31118f5 commit 43ecce4

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

findTheOldest/findTheOldest.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
let findTheOldest = function() {
2-
1+
let findTheOldest = function(object) {
2+
const year = new Date().getFullYear()
3+
object.sort((a, b) => (a.yearOfDeath || year) - (a.yearOfBirth || year) > (b.yearOfDeath || year) - (b.yearOfBirth || year) ? -1 : 1)
4+
return object[0]
35
}
46

57
module.exports = findTheOldest

findTheOldest/findTheOldest.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('findTheOldest', function() {
2121
]
2222
expect(findTheOldest(people).name).toEqual('Ray');
2323
});
24-
xit('finds the oldest person if someone is still living', function() {
24+
it('finds the oldest person if someone is still living', function() {
2525
const people = [
2626
{
2727
name: 'Carly',
@@ -40,7 +40,7 @@ describe('findTheOldest', function() {
4040
]
4141
expect(findTheOldest(people).name).toEqual('Ray');
4242
});
43-
xit('finds the oldest person if the OLDEST is still living', function() {
43+
it('finds the oldest person if the OLDEST is still living', function() {
4444
const people = [
4545
{
4646
name: 'Carly',

0 commit comments

Comments
 (0)
0