Created
January 2, 2017 18:11
-
-
Save PantherHawk/0fdc95e3a7a2e5b908e81292ffa6305d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* a) modelling our solar system */ | |
function convertDistance(planet) { | |
var kmDistance = planet.distance * 150000000; | |
return kmDistance + ' km.'; | |
} | |
function convertMass(planet) { | |
var kgMass = planet.mass * 5.97; | |
return kgMass + ' 10^24 kg.'; | |
} | |
var solarSystem = { | |
distanceCtrGalaxy: 28000 | |
age: 5000000000 | |
planets: [{ | |
name: 'Mercury', | |
mass: 0.055, | |
distance: 3.4, | |
satelites: [], | |
terrestrial: true, | |
giant: false, | |
gasGiant: false | |
}, { | |
name: 'Venus', | |
mass: 0.81, | |
distance: 0.7, | |
satelites: [], | |
terrestrial: true, | |
giant: false, | |
gasGiant: false | |
}, { | |
name: 'Earth', | |
mass: 1, | |
distance: 1, | |
satelites: ['Moon'], | |
terrestrial: true, | |
giant: false, | |
gasGiant: false | |
}, { | |
name: 'Mars', | |
mass: 0.107, | |
distance: 1.5, | |
satelites: ['Phobos', 'Deimos'], | |
terrestrial: true, | |
giant: false, | |
gasGiant: false | |
}, { | |
name: 'Jupiter', | |
mass: 318, | |
distance: 5.2, | |
satelites: ['Io', 'Europa', 'Ganymede', 'Callisto'], | |
terrestrial: false, | |
giant: true, | |
gasGiant: true | |
}, { | |
name: 'Saturn', | |
mass: 95, | |
distance: 9.5, | |
satelites: ['Mimas', | |
'Enceladus', | |
'Tethys', | |
'Dionne', | |
'Rhea', | |
'Titan', | |
'Hyperion', | |
'Iapetus', | |
'Phoebe' | |
], | |
terrestrial: false, | |
giant: true, | |
gasGiant: true | |
}, { | |
name: 'Uranus', | |
mass: 14, | |
distance: 19.2, | |
satelites: ['Puck', 'Miranda', 'Ariel', 'Umbriel', 'Titania', 'Oberon'], | |
terrestrial: false, | |
giant: true, | |
gasGiant: false | |
}, { | |
name: 'Neptune', | |
mass: 17, | |
distance: 30.1, | |
satelites: ['Proteus', 'Triton', 'Neroid'], | |
terrestrial: false, | |
giant: true, | |
gasGiant: false | |
}] | |
comets: 3295 | |
} | |
/* b) function which takes two inputs and spits out their range */ | |
var arr = []; | |
function range(start, end){ | |
if(start === end){ | |
return arr; | |
}else if (start > end) { | |
return arr; | |
} else { | |
arr.push(start); | |
console.log(arr); | |
} | |
return range(start + 1, end); | |
} | |
/* c) given an array of objects holding name objects with first, | |
middle, last name key-values, return the longest name in the array */ | |
function fullName(obj) { | |
var name = ''; | |
for (var key in obj['name']){ | |
name += obj['name'][key] + ' '; | |
} | |
return name.slice(0, -1); | |
} | |
function longestName(array) { | |
var longest = ''; | |
for(var i = 0; i < array.length; i++){ | |
console.log(fullName(array[i])); | |
if (fullName(array[i]).length > longest.length){ | |
longest = fullName(array[i]); | |
} | |
} | |
return longest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment