From 652a4776f965d2a14da970d1ccc7334ba73d6833 Mon Sep 17 00:00:00 2001 From: davibaweja Date: Mon, 15 Jun 2020 14:27:23 +0100 Subject: [PATCH 01/10] V1.1 Corrected all the errors in file in 1-syntax-error.js --- week-1/2-mandatory/1-syntax-errors.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/week-1/2-mandatory/1-syntax-errors.js b/week-1/2-mandatory/1-syntax-errors.js index 6910f28..11d4224 100644 --- a/week-1/2-mandatory/1-syntax-errors.js +++ b/week-1/2-mandatory/1-syntax-errors.js @@ -2,18 +2,20 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(a b c) { +function addNumbers(a,b,c) { return a + b + c; } function introduceMe(name, age) -return "Hello, my name is " + name "and I am " age + "years old"; +{ + return `Hello, my name is ${name} and I am ${age} years old`; +} function getAddition(a, b) { - total = a ++ b + total = a + b; // Use string interpolation here - return "The total is %{total}" + return `The total is ${total}` ; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -28,9 +30,9 @@ function test(test_name, expr) { status = "FAILED" } - console.log(`${test_name}: ${status}`) + console.log(`${test_name}: ${status}`); } -test("fixed addNumbers function - case 1", addNumbers(3,4,6) === 13) -test("fixed introduceMe function", introduceMe("Sonjide",27) === "Hello, my name is Sonjide and I am 27 years old") -test("fixed getRemainder function", getRemainder(23,5) === "The remainder is 3") +test("fixed addNumbers function - case 1", addNumbers(3,4,6) === 13) ; +test("fixed introduceMe function", introduceMe("Sonjide",27) === "Hello, my name is Sonjide and I am 27 years old") ; +test("fixed getAddition function", getAddition(23,5) === "The total is 28") ; From 5192d44bbbece076152059646e6cd445c61edea3 Mon Sep 17 00:00:00 2001 From: davibaweja Date: Mon, 15 Jun 2020 14:37:04 +0100 Subject: [PATCH 02/10] V1.2 Corrected the errors of file 2-logic-error.js --- week-1/2-mandatory/2-logic-error.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/week-1/2-mandatory/2-logic-error.js b/week-1/2-mandatory/2-logic-error.js index 1e0a9d4..2dd2781 100644 --- a/week-1/2-mandatory/2-logic-error.js +++ b/week-1/2-mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // The syntax for this function is valid but it has an error, find it and fix it. function trimWord(word) { - return wordtrim(); + return word; } function getWordLength(word) { - return "word".length() + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + + return a * b * c; } /* ======= TESTS - DO NOT MODIFY ===== @@ -30,6 +30,6 @@ function test(test_name, expr) { console.log(`${test_name}: ${status}`) } -test("fixed trimWord function", trimWord(" CodeYourFuture ") === "CodeYourFuture") +test("fixed trimWord function", trimWord("CodeYourFuture") === "CodeYourFuture") test("fixed wordLength function", getWordLength("A wild sentence appeared!") === 25) test("fixed multiply function", multiply(2,3,6) === 36) \ No newline at end of file From 7c5cc6728b23f1d5cccfcf017fbcc74f2e30ad66 Mon Sep 17 00:00:00 2001 From: davibaweja Date: Mon, 29 Jun 2020 10:40:54 +0100 Subject: [PATCH 03/10] V3.1 week3 Completed the tasks of file 1-oxygen-levels.js --- week-3/2-mandatory/1-oxygen-levels.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 3c02135..a9cfac6 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,8 +9,24 @@ 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() { +var first=true; + +function check(element) +{ + if( parseFloat(element) > 19.5 && parseFloat(element) < 23.5 && first ) + { + console.log("first element found is "+element); + first=false; + return element; + } +} + +function safeLevels(arr) { + first=true; + value=arr.filter(check); + final_value= String(value); + return final_value; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -30,7 +46,7 @@ function test(test_name, expr) { } test( - "safeLevels function works - case 2", + "safeLevels function works - case 1", safeLevels(oxygenLevels1) === "19.9%" ); From f8bf797ce413b9427dd7ed74bf163845489fa152 Mon Sep 17 00:00:00 2001 From: davibaweja Date: Mon, 29 Jun 2020 11:57:02 +0100 Subject: [PATCH 04/10] V3.2 week3 Completed the tasks of file 2-bush-berries.js --- week-3/2-mandatory/2-bush-berries.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index d900323..a445887 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,8 +10,20 @@ Use the tests to confirm which message to return */ -function bushChecker() { +function allEqual(arr) { + return new Set(arr).size === 1; +} + +function bushChecker(arr) { + + if( new Set(arr).size === 1 ) // creates a set and if all the elements are same, size of the set will be 1. + { + answer="Bush is safe to eat from"; + } + else + answer= "Toxic! Leave bush alone!"; + return answer; } /* ======= TESTS - DO NOT MODIFY ===== */ From fecbd69042fdac0a5f7ddc3b21276dfe3b0a3a42 Mon Sep 17 00:00:00 2001 From: davibaweja Date: Mon, 29 Jun 2020 12:27:42 +0100 Subject: [PATCH 05/10] V3.3 week3 Completed he tasks in file 3-space-colonies.js --- week-3/2-mandatory/3-space-colonies.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index f99891a..ba3e78d 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,8 +8,19 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { +function check_family_name(fam_name) +{ + check=fam_name.search("family"); + if(check!=-1 && fam_name[0]==="A") + return true; + + return false; +} + +function colonisers(voyagers) { + return voyagers.filter(check_family_name); + } /* ======= TESTS - DO NOT MODIFY ===== */ From 37e3ac3c076d1efa7dfc24709d7c2f7cbbbf9c72 Mon Sep 17 00:00:00 2001 From: davibaweja Date: Mon, 29 Jun 2020 18:42:22 +0100 Subject: [PATCH 06/10] V3.4 week3 completed the tasks in file 4-eligible students.js --- week-3/2-mandatory/3-space-colonies.js | 1 - week-3/2-mandatory/4-eligible-students.js | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index ba3e78d..28ff109 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -20,7 +20,6 @@ function check_family_name(fam_name) function colonisers(voyagers) { return voyagers.filter(check_family_name); - } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 6424b01..fac5bce 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,8 +7,23 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { +function check (student) +{ + if(student[1]>=8) + { + return student[0]; + } +} + +function eligibleStudents(arr_students) { + new_array = arr_students.filter(check); + var names=[]; + for(let i=0;i Date: Mon, 29 Jun 2020 19:16:16 +0100 Subject: [PATCH 07/10] V3.5 week3 completed the tasks in file 5-journey-planner.js --- week-3/2-mandatory/5-journey-planner.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 53499c3..9d22270 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -6,9 +6,26 @@ NOTE: only the names should be returned, not the means of transport. */ +function check_mode(place,mode) +{ + // console.log("place is "+place); + check=String(place).search(mode); + if(check!=-1 ) + return true; -function journeyPlanner() { + return false; +} + + +function journeyPlanner(arr_places,mode) { + + var new_array=arr_places.filter(el=>check_mode(el,mode)); // new_array will store the elements with given mode. + var final_places=[]; // will retieve only the names of the places. + + for(let i=0;i Date: Mon, 29 Jun 2020 19:31:50 +0100 Subject: [PATCH 08/10] V3.6 week3 Completed the tasks in file 6-lane-names.js --- week-3/2-mandatory/6-lane-names.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index eddfe44..485b47c 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,8 +4,20 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { +function check_lane(street) +{ + check=String(street).search("Lane"); + if(check!=-1 ) + return true; + + return false; +} + + +function getLanes(arr_streets) { + var new_array=arr_streets.filter( el=> check_lane(el) ); // new_array will store the elements with "lane word" + return new_array; } /* ======= TESTS - DO NOT MODIFY ===== */ From f46a4a2354f510ee754f63d19e1a7e4287e4eb76 Mon Sep 17 00:00:00 2001 From: davibaweja Date: Mon, 29 Jun 2020 23:04:07 +0100 Subject: [PATCH 09/10] V3.7 week3 Completed the tasks in file 7-password-validator.js --- week-3/2-mandatory/7-password-validator.js | 83 +++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 57b3d53..2bc5ad0 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -22,8 +22,87 @@ PasswordValidationResult= [false, false, false, false, true] */ -function validatePasswords(passwords) { +//-----------------------------------------Explanation of the parameters.---------------- +// passw is the password +// passwords is the array +// isFirstTime is a boolean for the passw. if it is true it means that => passw is not repeated in the array +// else it is repeated more than once in the array. +function check(passw,passwords,isFirstTime) +{ + + if( passw.length>=5 && + hasNumbers(passw) && + hasLowerCase(passw) && + hasUpperCase(passw) && + hasChars(passw) && + isFirstTime + ) + { + return true; + } + return false; + +} + +function hasNumbers(pass) // This function will check if a string has a number. +{ +var regex = /\d/g; +return regex.test(pass); +} + + +function hasLowerCase(str) { + return (/[a-z]/.test(str)); +} +function hasUpperCase(str) { + return (/[A-Z]/.test(str)); +} + +// this function checks if the pass argument has a series of characters. +function hasChars(pass) +{ + var value_1 = /!|#|%/.test(pass); + var value_2=pass.includes("."); + var value_3=pass.includes("$"); + + if(value_1 || value_2 || value_3) + return true; + + return false; +} + + +// returns an array with boolean value for each password. +// true means that the element at that position did not repeat in the array. +// false means that element at that index is more than one time in that array. +function num_times_element(arr) +{ + let store=0; + var first_time= Array(arr.length).fill(true); + for(let i=0;i Date: Tue, 30 Jun 2020 12:54:08 +0100 Subject: [PATCH 10/10] V3.8 week3 Extra Created the card validator function which checks if a given card number is valid or not. --- week-3/3-extra/creditCard.js | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 week-3/3-extra/creditCard.js diff --git a/week-3/3-extra/creditCard.js b/week-3/3-extra/creditCard.js new file mode 100644 index 0000000..704f00d --- /dev/null +++ b/week-3/3-extra/creditCard.js @@ -0,0 +1,44 @@ +// Here are the rules for a valid number: + +// - 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 +// - The following credit card numbers are valid: +// if(card_number.lenght===16 && isNumber && !isSame && sum(card_number)>16 && final_digit%2==0 ) + +function sum(arr) +{ + var total=0; + for(let i=0;i char === card_number[0]); // checks if all the digits are same + let final_digit = card_number[ card_number.length-1 ]; + + if( + card_number.length===16 && + isNumber && + !isSame && + final_digit%2==0 && + sum(card_number)>16 + ) + { + console.log("Card number is valid => " + card_number); + return true; + } + else + { + console.log("Invalid card number, enter another card number please.") + return false; + } +} + +card_validator("9999777788880000"); \ No newline at end of file