Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.
10 changes: 7 additions & 3 deletions week-3/1-exercises/A-array-find/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
*/

// write your code here
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Selam abi :)

function x(word){
return word.length>7 && word[0]==='A'
}


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

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

console.log(longNameThatStartsWithA);
var newArr = names.find(x);
console.log(newArr);

/* EXPECTED OUTPUT */
// "Alexandra"
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 @@ -16,6 +16,10 @@ var students = ["Islam", "Lesley", "Harun", "Rukmini"];
var mentors = ["Daniel", "Irina", "Mozafar", "Luke"];

var pairs = pairsByIndex.map(function(indexes) {
if(indexes===null)
{
process.exit(1);
}
var student = students[indexes[0]];
var mentor = mentors[indexes[1]];
return [student, mentor];
Expand Down
8 changes: 8 additions & 0 deletions week-3/1-exercises/C-array-every/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ var group = ["Austine", "Dany", "Swathi", "Daniel"];

var groupIsOnlyStudents; // complete this statement

function election (newarr){
return (students.includes(newarr))

}

var groupIsOnlyStudents = group.every(election); // complete this statement


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

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

var pairsByIndex; // Complete this statement

var pairsByIndex = pairsByIndex.filter(x=>Array.isArray(x)&& x.length===2) // Complete this statement
// completed with arrow function with filter and is Array methods.
var students = ["Islam", "Lesley", "Harun", "Rukmini"];
var mentors = ["Daniel", "Irina", "Mozafar", "Luke"];

Expand Down
3 changes: 3 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,6 @@

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

const newArr = numbers.map(x=>x*100)

console.log(newArr);
16 changes: 16 additions & 0 deletions week-3/1-exercises/F-array-forEach/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@
*/

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
function fizzbuzz(){
for(let i = 1; i <= 100; i++){
if(i % 3 === 0 && i % 5 === 0){
console.log("FizzBuzz");
}else if (i % 3 === 0){
console.log("Fizz");
}else if (i % 5 === 0){
console.log("Buzz");
}else{
console.log(i);
}
}
return arr[i];
}

fizzbuzz();

/* 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(2,8) // complete this statement

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

function capitalise(str) {}

function capital (x){
var name = "x";
const nameCapitalized = x.charAt(0).toUpperCase() + x.slice(1)
console.log(nameCapitalized);
}
capital('daniel');
capital('hello');
/*
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 country.includes(); // complete this statement
}

/*
Expand Down
6 changes: 3 additions & 3 deletions week-3/2-mandatory/1-oxygen-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ To be safe to land on, a planet needs to have an Oxygen level between 19.5% and
Write a function that finds the first safe oxygen level in the array - Oxygen between 19.5% and 23.5%
*/

function safeLevels() {

}
function safeLevels(x) {
return x.find(level => level > "19.5%" && level < "23.5%");
}

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

Expand Down
10 changes: 7 additions & 3 deletions week-3/2-mandatory/2-bush-berries.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

Use the tests to confirm which message to return
*/

function bushChecker() {

function pinkBerry(x){
return x ==="pink";
}
function bushChecker(x) {
if(x.every(pinkBerry))
return "Bush is safe to eat from"
return "Toxic! Leave bush alone!"
}

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

function colonisers() {

function colonisers(x) {
return x.filter(x=>x[0] ==='A' && x.length >7);
}

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

function eligibleStudents() {

function eligibleStudents(x) {

return x.filter(y => (y[1] >= 8 ? y[1]:'')).map(a=>a[0])
}

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

function journeyPlanner() {
function journeyPlanner(a,b) {
return a.filter(x => x.includes(b)).map(x => x[0])
}


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

const londonLocations = [
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(y) {
return y.filter(x => x.includes('Lane'));
}

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

*/
let numbers = [0,1,2,3,4,5,6,7,8,9];

function validatePasswords(passwords) {

return passwords.map(x => (x.length >= 5 && numbers.some(h => x.includes(h)) && x.toLowerCase() != x && x.toUpperCase() != x && (x.indexOf('!') != -1 || x.indexOf('#') != -1 || x.indexOf('$') != -1 || x.indexOf('%') != -1 || x.indexOf('.') != -1)) ? true : false)
}

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

const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"]
const passwords2 = ["StUFf27%", "Pl3nty!", "Jai33", "shajsaUA**&&", "Pl3nty!"]
const passwords2 = ["StUFf27%", "Pl3nty!", "Jai33", "shajsaUA**&&", "Pl3nty"]

const util = require('util');

Expand Down