Skip to content

Latest commit

 

History

History
458 lines (353 loc) · 13.5 KB

README.md

File metadata and controls

458 lines (353 loc) · 13.5 KB

JavaScript

21 days coding challenge by Lighthouse Labs

Completed one challenge a day from November 22 until December 12 to develop a daily coding habit.


| 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 |

image


⭐ Challenge 1

✔️ Solution

const parseMessage = (origin, message) => {
return origin + ": " + message;
}
___________________________________________________________________________________________________________________

⭐ Challenge 2

✔️ Solution

const generateAstronautTag = (astronaut) => {
return astronaut.prefix + ": " +  astronaut.firstName + " \"" + astronaut.nickname + "\" " + astronaut.lastName;
}
___________________________________________________________________________________________________________________

⭐ Challenge 3

✔️ Solution

const checkGaugeStatus = (gauge) => {

if(gauge.current>=gauge.min && gauge.current <= gauge.max){
  
  return true;
  
}else{
  
  return false;

}
}
___________________________________________________________________________________________________________________

⭐ Challenge 4

✔️ Solution

const switchToggle = (toggle) => {
toggle.isOn = !toggle.isOn;
return toggle;
}
___________________________________________________________________________________________________________________

⭐ Challenge 5

✔️ Solution

const addJobToAstronaut = (astronaut, job) => {
astronaut.job = job;
return astronaut;
}
___________________________________________________________________________________________________________________

⭐ Challenge 6

✔️ Solution

const addAstronautToRoster = (roster, astronaut) => {
roster.push(astronaut);
return roster;
}
___________________________________________________________________________________________________________________

⭐ Challenge 7

✔️ Solution

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;
}
___________________________________________________________________________________________________________________

⭐ Challenge 8

✔️ Solution

const countActiveAstronauts = (roster) => {
var count = 0;

for(i=0; i<roster.length; i++){
  count++;
}
return count;
}
___________________________________________________________________________________________________________________

⭐ Challenge 9

✔️ Solution

const listAstronautJobs = (roster) => {
var arr = [];

for(i = 0; i < roster.length; i++){
  arr.push(roster[i].job);
}
return arr;
}
___________________________________________________________________________________________________________________

⭐ Challenge 10

✔️ Solution

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);
}
___________________________________________________________________________________________________________________

⭐ Challenge 11

✔️ Solution

const bookFreePlatform = (platformList, missionDate) => {
for(i=0; i<platformList.length; i++){
  if(platformList[i].bookDate === undefined){
    platformList[i].bookDate = missionDate;
    break;
  }
}
return platformList;
}
___________________________________________________________________________________________________________________

⭐ Challenge 12

✔️ Solution

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;
}
___________________________________________________________________________________________________________________

⭐ Challenge 13

✔️ Solution

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;
}
___________________________________________________________________________________________________________________

⭐ Challenge 14

✔️ Solution

const switchAllTogglesOn = (toggleList) => {
for(i=0; i<toggleList.length; i++){
  toggleList[i].isOn = true;
}
return toggleList;
}
___________________________________________________________________________________________________________________

⭐ Challenge 15

✔️ Solution

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
}
}
___________________________________________________________________________________________________________________

⭐ Challenge 16

✔️ Solution

const getAverageSpeed = (firstPosition, secondPosition) => {
distance = secondPosition.altitude - firstPosition.altitude;
time = secondPosition.time - firstPosition.time;
speed = distance/time;
return parseFloat(speed.toFixed(1));
}
___________________________________________________________________________________________________________________

⭐ Challenge 17

✔️ Solution

const switchSpecificToggle = (toggleList, specificToggle) => {
  for(i=0; i<toggleList.length; i++){
    if(toggleList[i].name == specificToggle){
      toggleList[i].isOn = true;
    }
  }
return toggleList;
}
___________________________________________________________________________________________________________________

⭐ Challenge 18

✔️ Solution

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;
}
}
___________________________________________________________________________________________________________________

⭐ Challenge 19

✔️ Solution

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;
}
___________________________________________________________________________________________________________________

⭐ Challenge 20

✔️ Solution

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;
}
___________________________________________________________________________________________________________________

⭐ Challenge 21

✔️ Solution

const parseMissionSummary = (exchanges, missionData) => {

var arr = [];

for(i=0; i<exchanges.length; i++){
  var str = exchanges[i].origin + ": " + exchanges[i].message;
  arr.push(str);
}

var obj = {};
obj.transcript = arr;
obj.missionData = missionData;
return obj;
}
__________________________________________________________________________________________________________________