File tree Expand file tree Collapse file tree 4 files changed +22
-3
lines changed
exercises/practice/space-age Expand file tree Collapse file tree 4 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 66 " ankorGH" ,
77 " cmccandless" ,
88 " draalger" ,
9+ " jagdish-15" ,
910 " JesseSingleton" ,
1011 " jscheffner" ,
1112 " kytrinyx" ,
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ const EARTH_TO_OTHER_PLANETS = {
1010} ;
1111
1212export const age = ( planet , seconds ) => {
13+ if ( ! EARTH_TO_OTHER_PLANETS [ planet ] ) {
14+ throw new Error ( 'not a planet' ) ;
15+ }
16+
1317 const earthYears = seconds / 31557600 ;
1418 const years = earthYears / EARTH_TO_OTHER_PLANETS [ planet ] ;
1519
Original file line number Diff line number Diff line change 1- # This is an auto-generated file. Regular comments will be removed when this
2- # file is regenerated. Regenerating will not touch any manually added keys,
3- # so comments can be added in a "comment" key.
1+ # This is an auto-generated file.
2+ #
3+ # Regenerating this file via `configlet sync` will:
4+ # - Recreate every `description` key/value pair
5+ # - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+ # - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+ # - Preserve any other key/value pair
8+ #
9+ # As user-added comments (using the # character) will be removed when this file
10+ # is regenerated, comments can be added via a `comment` key.
411
512[84f609af-5a91-4d68-90a3-9e32d8a5cd34 ]
613description = " age on Earth"
@@ -25,3 +32,6 @@ description = "age on Uranus"
2532
2633[80096d30-a0d4-4449-903e-a381178355d8 ]
2734description = " age on Neptune"
35+
36+ [57b96e2a-1178-40b7-b34d-f3c9c34e4bf4 ]
37+ description = " invalid planet causes error"
Original file line number Diff line number Diff line change @@ -33,4 +33,8 @@ describe('Space Age', () => {
3333 xtest ( 'age on Neptune' , ( ) => {
3434 expect ( age ( 'neptune' , 1821023456 ) ) . toEqual ( 0.35 ) ;
3535 } ) ;
36+
37+ xtest ( 'invalid planet causes error' , ( ) => {
38+ expect ( ( ) => age ( 'Sun' , 680804807 ) ) . toThrow ( new Error ( 'not a planet' ) ) ;
39+ } ) ;
3640} ) ;
You can’t perform that action at this time.
0 commit comments