Skip to content
This repository has been archived by the owner on Oct 26, 2020. It is now read-only.

Week4 homework #929

Open
wants to merge 15 commits into
base: scotland-class4
Choose a base branch
from
Prev Previous commit
Next Next commit
Merge branch 'scotland-class4' into week4
  • Loading branch information
alastair87 authored Jun 14, 2020
commit 13c7331a5e3d535092a7c8e1fe9181be86f98a8c
3 changes: 3 additions & 0 deletions week-4/Homework/mandatory/3-translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ or in the event of an invalid input.


function greet(language) {

if (typeof language === "string") {
let lang = language.toLowerCase();
if (Object.keys(languages).includes(lang)) {
Expand All @@ -48,6 +49,8 @@ console.log(greet("irish"));
console.log(greet("FINNish"));
console.log(greet("russian"));
console.log(greet(6));
return languages[language];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return outside the function can be removed as it doesn't do anything.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not what I have in my file. there are no lines 32,33 and 52,53. Why are they shown here?


/*
Test your function works correctly calling it inside a console.log(), for each one of these cases:
Expand Down
35 changes: 34 additions & 1 deletion week-4/InClass/E-arrays-of-objects/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ let destination4 = {
};

let travelDestinations = [
week4
destination1,
destination2,
destination3,
destination4,
destination1,
destination2,
destination3,
destination4
scotland-class4
];

// [
Expand All @@ -44,7 +50,6 @@ let travelDestinations = [
// {destinationName: "Dublin", distanceKms: 350},
// ]

// ["Dublin", "Paris", "Edinburgh"]

let destinationNamesWithin500Kms = travelDestinations
.filter((destination) => destination.distanceKms <= 500)
Expand All @@ -68,11 +73,36 @@ let destinationNamesMoreThan300KmsAwayByTrain = travelDestinations
/* it doesn't work with forEach() and given consol.log() */

// Complete here (PRINT THE RESULT IN THE CONSOLE USING FOREACH)
=======
// ["Dublin", "Paris", "Edinburgh"]


// 1. Print in the console
// 2. all the destination names
// 3. more than 300 kms far away and reachable by train.

function isReachable(destination) {
let isFar = destination.distanceKms > 300;
let trainReachable = destination.transportations.includes("train");
return isFar && trainReachable;
}

let reachableDestinations = travelDestinations.filter(isReachable);


function transformDestination(destination) {
let destinationName = destination.destinationName;
return destinationName;
}

let destinationNames = reachableDestinations.map(transformDestination);


function printToConsole(destinationName) {
console.log(destinationName);
}


console.log(
`Question 1) Expected result: Edinburgh,Dublin, actual result: ${destinationNamesWithin500Kms}`
);
Expand All @@ -82,3 +112,6 @@ console.log(
console.log(
`Question 3) Expected result: London,Paris, actual result: ${destinationNamesMoreThan300KmsAwayByTrain}`
);

destinationNames.forEach(printToConsole);

You are viewing a condensed version of this merge commit. You can view the full changes here.