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

GT JS Week3 #74

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions week-3/1-exercises/A-array-find/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*/

// write your code here
function findLongNameThatStartsWithA(arr){
return arr.find(item => item.startsWith("A") && item.length > 7);
}

var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"];

Expand Down
4 changes: 4 additions & 0 deletions week-3/1-exercises/B-array-some/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]];
// If there is a null value in the array exit the program with the error code
// https://nodejs.org/api/process.html#process_process_exit_code
// process.exit(1);
if(pairsByIndex.some(item => item === null)){
process.exit(1);
}


var students = ["Islam", "Lesley", "Harun", "Rukmini"];
var mentors = ["Daniel", "Irina", "Mozafar", "Luke"];
Expand Down
2 changes: 1 addition & 1 deletion week-3/1-exercises/C-array-every/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"];
var group = ["Austine", "Dany", "Swathi", "Daniel"];

var groupIsOnlyStudents; // complete this statement
var groupIsOnlyStudents = group.every(item => students.find(student => student === item)); // complete this statement

if (groupIsOnlyStudents) {
console.log("The group contains only students");
Expand Down
2 changes: 1 addition & 1 deletion week-3/1-exercises/D-array-filter/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"];

var pairsByIndex; // Complete this statement
var pairsByIndex = pairsByIndexRaw.filter(item => Array.isArray(item) && item.length === 2 ); // Complete this statement

var students = ["Islam", "Lesley", "Harun", "Rukmini"];
var mentors = ["Daniel", "Irina", "Mozafar", "Luke"];
Expand Down
23 changes: 23 additions & 0 deletions week-3/1-exercises/E-array-map/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,26 @@

var numbers = [0.1, 0.2, 0.3, 0.4, 0.5];

function multiplyByHundred(item){
return item * 100;
}

let numbers1 = numbers.map(multiplyByHundred);

console.log(numbers1);

let numbers2 = numbers.map(function multiplyBy100(item){return item * 100;});

console.log(numbers2);

let numbers3 = numbers.map(function (item){return item * 100;});

console.log(numbers3);

let numbers4 = numbers.map(item => {return item * 100;});

console.log(numbers4);

let numbers5 = numbers.map(item => item * 100);

console.log(numbers5);
11 changes: 10 additions & 1 deletion week-3/1-exercises/F-array-forEach/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
*/

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];

arr.forEach((item) => {
if(item % 3 === 0 && item % 5 === 0){
console.log("FizzBuzz");
}else if (item % 3 === 0){
console.log("Fizz");
}else if(item % 5 === 0){
console.log("Buzz");
}else {console.log(item);}
}
);
/* EXPECTED OUTPUT */

/*
Expand Down
2 changes: 1 addition & 1 deletion week-3/1-exercises/G-array-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

var numbers = [3, 2, 1];
var sortedNumbers; // complete this statement
var sortedNumbers = numbers.sort(); // complete this statement

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
2 changes: 1 addition & 1 deletion week-3/1-exercises/G-array-methods/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
var mentors = ["Daniel", "Irina", "Rares"];
var students = ["Rukmini", "Abdul", "Austine", "Swathi"];

var everyone; // complete this statement
var everyone = mentors.concat(students); // complete this statement

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
4 changes: 2 additions & 2 deletions week-3/1-exercises/H-array-methods-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var everyone = [
"Swathi"
];

var firstFive; // complete this statement
var lastFive; // complete this statement
var firstFive = everyone.slice(0, 5); // complete this statement
var lastFive = everyone.slice(-5); // complete this statement

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
6 changes: 5 additions & 1 deletion week-3/1-exercises/H-array-methods-2/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
Tip: use the string method .split() and the array method .join()
*/

function capitalise(str) {}
function capitalise(str) {
let arr = str.split("");
arr[0] = arr[0].toUpperCase();
return arr.join("");
}

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
2 changes: 1 addition & 1 deletion week-3/1-exercises/H-array-methods-2/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"];

function isInUK(country) {
return; // complete this statement
return ukNations.includes(country); // complete this statement
}

/*
Expand Down
3 changes: 2 additions & 1 deletion week-3/2-mandatory/1-oxygen-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ To be safe, they need to land on the first unamed planet that has Oxygen levels
Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5%
*/

function safeLevels() {
function safeLevels(arr) {
return arr.find(oxLevel => parseFloat(oxLevel) > 19.5 && parseFloat(oxLevel) < 23.5);

}

Expand Down
7 changes: 5 additions & 2 deletions week-3/2-mandatory/2-bush-berries.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
Use the tests to confirm which message to return
*/

function bushChecker() {

function bushChecker(arr) {
if(arr.some(berryColor => berryColor != "pink")){
return "Toxic! Leave bush alone!";
}
return "Bush is safe to eat from";
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
3 changes: 2 additions & 1 deletion week-3/2-mandatory/3-space-colonies.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
NOTE: don't include any element that is not a "family".
*/

function colonisers() {
function colonisers(arr) {
return arr.filter(item => item.startsWith("A") && item.includes("family"));

}

Expand Down
4 changes: 2 additions & 2 deletions week-3/2-mandatory/4-eligible-students.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
- Returns an array containing only the names of the who have attended AT LEAST 8 classes
*/

function eligibleStudents() {

function eligibleStudents(arr) {
return arr.filter(item => item[1] > 7).map(item => item[0]);
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
4 changes: 2 additions & 2 deletions week-3/2-mandatory/5-journey-planner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
NOTE: only the names should be returned, not the means of transport.
*/

function journeyPlanner() {

function journeyPlanner(arr, by) {
return arr.filter(item => item.includes(by)).map(item => item[0]);
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
4 changes: 2 additions & 2 deletions week-3/2-mandatory/6-lane-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Write a function that will return all street names which contain 'Lane' in their name.
*/

function getLanes() {

function getLanes(arr) {
return arr.filter(item => item.includes("Lane"));
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
21 changes: 20 additions & 1 deletion week-3/2-mandatory/7-password-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,30 @@ Expected Result:
PasswordValidationResult= [false, false, false, false, true]

*/

function validatePasswords(passwords) {
return passwords.map((password,index,arr) => {

let passwordArray = password.split("");

return password.length > 5 && // check the min length of password
// check if the password is duplicated
index === arr.indexOf(password) &&
// check if the password have uppercase letter
passwordArray.some(item => item >= "A" && item <= "Z") &&
// check if the password have lowercase letter
passwordArray.some(item => item >= "a" && item <= "z") &&
// check if the password have number
passwordArray.some(item => item >= "0" && item <= "9") &&
// check if the password have special symbols
passwordArray.some(item =>["!", "#", "$", "%", "."].includes(item)) &&
/* this validation for exception of all symbols that are not English alphabet symbols,
not numbers or non-alphanumeric symbols ("!", "#", "$", "%", "."). */
passwordArray.every(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") ||
(item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].includes(item));
});
}


/* ======= TESTS - DO NOT MODIFY ===== */

const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"]
Expand Down
4 changes: 3 additions & 1 deletion week-3/2-mandatory/8-codewars.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ Today, you'll be using a platform called [CodeWars](https://codewars.com) to hel
- [people in bus](https://www.codewars.com/kata/number-of-people-in-the-bus/train/javascript)
- [sum without highest and lowest](https://www.codewars.com/kata/sum-without-highest-and-lowest-number/train/javascript)
- [reveersed array of digits](https://www.codewars.com/kata/convert-number-to-reversed-array-of-digits/train/javascript)
- [slash sum of negatives](https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives/train/javascript)
- [slash sum of negatives](https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives/train/javascript)


38 changes: 38 additions & 0 deletions week-3/3-extra/card-validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// - Number must be 16 digits, all of them must be numbers
// - You must have at least two different digits represented (all of the digits cannot be the same)
// - The final digit must be even
// - The sum of all the digits must be greater than 16

function isBankCardValid(cardNumber){
let numberArray = cardNumber.split("");

firstGroup = cardNumber.slice(0, 4);
secondGroup = cardNumber.slice(4, 8);
thirdGroup = cardNumber.slice(8, 12);
fourthGroup = cardNumber.slice(12);
if (numberArray.length !== 16){
return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.length`;
}// check if a length of card number equals 16
if (numberArray.some(number => !(number >=0 && number <= 9))){
return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. There is non number characters.`;
}// check if all characters in card number are digit
if(numberArray.reduce((accumulator, number) => accumulator + parseInt(number),0) <= 16){
return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. The summ of numbers is lower than 16`;
}// check if a summ of all digits is greater or equals to 16
if(numberArray[15] % 2 === 1){
return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. The last number is not even.`;
}// check if the last is an even digit
if(numberArray.every((number, index, arr) => number === numberArray[0])){
return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. All numbers the same.`;
}// check if all didgits are the same
return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is valid.`;

}
console.log(isBankCardValid("9999777788880000"));
console.log(isBankCardValid("6666666666661666"));
console.log(isBankCardValid("a92332119c011112"));
console.log(isBankCardValid("4444444444444444"));
console.log(isBankCardValid("1111111111111110"));
console.log(isBankCardValid("6666666666666661"));