| Challenge 1 | Challenge 2 | Challenge 3 | Challenge 4 | Challenge 5 | Challenge 6 | Challenge 7 | Challenge 8 | Challenge 9 | Challenge 10 | Challenge 11 | Challenge 12 | Challenge 13 | Challenge 14 | Challenge 15 | Challenge 16 | Challenge 17 | Challenge 18 | Challenge 19 | Challenge 20 | Challenge 21 |
___________________________________________________________________________________________________________________
const generateAstronautTag = (astronaut) => {
return astronaut.prefix + ": " + astronaut.firstName + " \"" + astronaut.nickname + "\" " + astronaut.lastName;
}
const checkGaugeStatus = (gauge) => {
if(gauge.current>=gauge.min && gauge.current <= gauge.max){
return true;
}else{
return false;
}
}
const addJobToAstronaut = (astronaut, job) => {
astronaut.job = job;
return astronaut;
}
const addAstronautToRoster = (roster, astronaut) => {
roster.push(astronaut);
return roster;
}
const storeWeatherConditions = (temperature, condition, windSpeed, windDirection) => {
newTemperature = Math.round((temperature - 32)/1.8);
newWindSpeed = Math.round(windSpeed*0.44704);
const structure = {
temperature:newTemperature,
condition:condition,
windSpeed:newWindSpeed,
windDirection:windDirection,
}
return structure;
}
const countActiveAstronauts = (roster) => {
var count = 0;
for(i=0; i<roster.length; i++){
count++;
}
return count;
}
const listAstronautJobs = (roster) => {
var arr = [];
for(i = 0; i < roster.length; i++){
arr.push(roster[i].job);
}
return arr;
}
const averageWindSpeed = (weatherEntries) => {
var count = 0;
var sum = 0;
for(i=0; i<weatherEntries.length; i++){
sum += weatherEntries[i].windSpeed;
count++;
}
return Math.round(sum/count);
}
const bookFreePlatform = (platformList, missionDate) => {
for(i=0; i<platformList.length; i++){
if(platformList[i].bookDate === undefined){
platformList[i].bookDate = missionDate;
break;
}
}
return platformList;
}
const parseTranscripts = (messages) => {
var arr = [];
var result = "";
for(i=0; i<messages.length; i++){
result = messages[i].origin + ": " + messages[i].message;
arr.push(result);
}
return arr;
}
const checkAllGauges = (gaugeList) => {
var result = true;
for(i=0; i<gaugeList.length; i++){
if(gaugeList[i].current < gaugeList[i].min ||
gaugeList[i].current > gaugeList[i].max){
result = false;
}
}
return result;
}
const switchAllTogglesOn = (toggleList) => {
for(i=0; i<toggleList.length; i++){
toggleList[i].isOn = true;
}
return toggleList;
}
const timeRemaining = (launchDate, missionName, fakeToday) => {
const today = fakeToday || new Date()
const firstDate = new Date(launchDate);
const secondDate = new Date(today);
const diffDays = Math.round(Math.abs((firstDate - secondDate) / (24 * 60 * 60 * 1000)));
return {missionName : missionName,
daysRemaining : diffDays
}
}
const getAverageSpeed = (firstPosition, secondPosition) => {
distance = secondPosition.altitude - firstPosition.altitude;
time = secondPosition.time - firstPosition.time;
speed = distance/time;
return parseFloat(speed.toFixed(1));
}
const switchSpecificToggle = (toggleList, specificToggle) => {
for(i=0; i<toggleList.length; i++){
if(toggleList[i].name == specificToggle){
toggleList[i].isOn = true;
}
}
return toggleList;
}
const chooseLunchWinner = (listOfChoices) => {
var cnt1 = 0;
var cnt2 = 0;
var first = listOfChoices[0];
for(i=0; i<listOfChoices.length; i++){
if(listOfChoices[i] == first){
cnt1++;
}else{
second = listOfChoices[i];
cnt2++;
}
}
if(cnt1>cnt2){
return first;
}else{
return second;
}
}
const organizeData = (receivedData) => {
var arr = [];
for(i=0; i<receivedData.length; i++){
arr.push(receivedData[i].type)
}
var newArr = arr.filter((value, index) => arr.indexOf(value) === index);
var obj = {};
for(i=0; i<newArr.length; i++){
var valueArr = [];
for(j=0; j<receivedData.length; j++){
if(newArr[i] == receivedData[j].type){
valueArr.push(receivedData[j].data);
obj[newArr[i]] = valueArr;
}
}
}
return obj;
}
const confirmReentryPlans = (speed, missionData, checks) => {
if(speed > checks.maxSpeed || speed < checks.minSpeed){
return false;
}
for(const key in missionData){
const check_key_length = checks.dataEntries[key];
const key_length = missionData[key].length;
if(key_length != check_key_length){
return false;
}
}
return true;
}