File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- let findTheOldest = function ( ) {
1+ let findTheOldest = function ( arr ) {
2+ const today = new Date ( ) ;
3+ const currYear = today . getFullYear ( ) ;
4+ arr . sort ( ( a , b ) => {
5+ return (
6+ ( b . yearOfDeath || currYear ) - b . yearOfBirth - ( ( a . yearOfDeath || currYear ) - a . yearOfBirth )
7+ ) ;
8+ } ) ;
29
3- }
10+ return arr [ 0 ] ;
11+ } ;
412
5- module . exports = findTheOldest
13+ module . exports = findTheOldest ;
Original file line number Diff line number Diff line change 1- let findTheOldest = require ( './findTheOldest' )
2-
3- describe ( 'findTheOldest' , function ( ) {
4- it ( 'finds the oldest person!' , function ( ) {
5- const people = [
6- {
7- name : 'Carly' ,
8- yearOfBirth : 1942 ,
9- yearOfDeath : 1970 ,
10- } ,
11- {
12- name : 'Ray' ,
13- yearOfBirth : 1962 ,
14- yearOfDeath : 2011
15- } ,
16- {
17- name : 'Jane' ,
18- yearOfBirth : 1912 ,
19- yearOfDeath : 1941
20- } ,
21- ]
22- expect ( findTheOldest ( people ) . name ) . toEqual ( 'Ray' ) ;
23- } ) ;
24- xit ( 'finds the oldest person if someone is still living' , function ( ) {
25- const people = [
26- {
27- name : 'Carly' ,
28- yearOfBirth : 2018 ,
29- } ,
30- {
31- name : 'Ray' ,
32- yearOfBirth : 1962 ,
33- yearOfDeath : 2011
34- } ,
35- {
36- name : 'Jane' ,
37- yearOfBirth : 1912 ,
38- yearOfDeath : 1941
39- } ,
40- ]
41- expect ( findTheOldest ( people ) . name ) . toEqual ( 'Ray' ) ;
42- } ) ;
43- xit ( 'finds the oldest person if the OLDEST is still living' , function ( ) {
44- const people = [
45- {
46- name : 'Carly' ,
47- yearOfBirth : 1066 ,
48- } ,
49- {
50- name : 'Ray' ,
51- yearOfBirth : 1962 ,
52- yearOfDeath : 2011
53- } ,
54- {
55- name : 'Jane' ,
56- yearOfBirth : 1912 ,
57- yearOfDeath : 1941
58- } ,
59- ]
60- expect ( findTheOldest ( people ) . name ) . toEqual ( 'Carly' ) ;
61- } ) ;
1+ let findTheOldest = require ( "./findTheOldest" ) ;
622
3+ describe ( "findTheOldest" , function ( ) {
4+ it ( "finds the oldest person!" , function ( ) {
5+ const people = [
6+ {
7+ name : "Carly" ,
8+ yearOfBirth : 1942 ,
9+ yearOfDeath : 1970 ,
10+ } ,
11+ {
12+ name : "Ray" ,
13+ yearOfBirth : 1962 ,
14+ yearOfDeath : 2011 ,
15+ } ,
16+ {
17+ name : "Jane" ,
18+ yearOfBirth : 1912 ,
19+ yearOfDeath : 1941 ,
20+ } ,
21+ ] ;
22+ expect ( findTheOldest ( people ) . name ) . toEqual ( "Ray" ) ;
23+ } ) ;
24+ it ( "finds the oldest person if someone is still living" , function ( ) {
25+ const people = [
26+ {
27+ name : "Carly" ,
28+ yearOfBirth : 2018 ,
29+ } ,
30+ {
31+ name : "Ray" ,
32+ yearOfBirth : 1962 ,
33+ yearOfDeath : 2011 ,
34+ } ,
35+ {
36+ name : "Jane" ,
37+ yearOfBirth : 1912 ,
38+ yearOfDeath : 1941 ,
39+ } ,
40+ ] ;
41+ expect ( findTheOldest ( people ) . name ) . toEqual ( "Ray" ) ;
42+ } ) ;
43+ it ( "finds the oldest person if the OLDEST is still living" , function ( ) {
44+ const people = [
45+ {
46+ name : "Carly" ,
47+ yearOfBirth : 1066 ,
48+ } ,
49+ {
50+ name : "Ray" ,
51+ yearOfBirth : 1962 ,
52+ yearOfDeath : 2011 ,
53+ } ,
54+ {
55+ name : "Jane" ,
56+ yearOfBirth : 1912 ,
57+ yearOfDeath : 1941 ,
58+ } ,
59+ ] ;
60+ expect ( findTheOldest ( people ) . name ) . toEqual ( "Carly" ) ;
61+ } ) ;
6362} ) ;
Original file line number Diff line number Diff line change 1- const getTheTitles = function ( ) {
2-
3- }
1+ const getTheTitles = function ( arr ) {
2+ return arr . map ( ( x ) => x . title ) ;
3+ } ;
44
55module . exports = getTheTitles ;
You can’t perform that action at this time.
0 commit comments