Skip to content
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
42 changes: 41 additions & 1 deletion 6-12_JS.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@ var list1 = [
// Your task is to return the number of JavaScript developers coming from Europe.
// Use .filter


function filter() {
var arr = list1.filter( function(dev){
return dev.language === 'JavaScript' && dev.continent === 'Europe';
});
return arr.length;
}

console.log(filter());

// Should return 3






// PROBLEM #2 //
// Your task is to return an array where each object will have a new property 'greeting' with the following string value:

Expand Down Expand Up @@ -49,6 +62,13 @@ var list1 = [
// you will need a block statement
// Use .map

var test = list1.map(function(list) {
list.greeting = `Hi ${list.firstName}, what do you like the most about ${list.language}`;
return list;
});

console.log(test);


// PROBLEM #3 //
// You will be given an array of objects (associative arrays in PHP) representing data about developers who have signed up to attend the next coding meetup that you are organising. The list is ordered according to who signed up first.
Expand All @@ -68,7 +88,19 @@ var list1 = [
// Use .find and an If statement, or ternary =)

// To embed javascript variables we use backticks ` and ${variable}
var dev = ()=> {

var dev = list1.find((list)=> {
return list.language === 'Python';
});
if(dev === undefined) {
return 'THere will be no Python developers';
}
return `${dev.firstName}, ${dev.country} of the first Python developer who has signed up.`
}


console.log(dev());

// PROBLEM #4 //
// You have an array of numbers.
Expand All @@ -85,6 +117,14 @@ var list1 = [
// const odds = arr.filter((n) => n % 2 != 0 )
// then sort it odds.sort((a,b) => a - b)

sortArray = (arr) => {
var odd = arr.filter((i)=> i % 2 != 0);
odd = odd.sort((a,b) => a - b);
var sorted = arr.map((num) => num % 2 != 0 ? odd.shift() : num);
return sorted;
}
console.log(sortArray([5, 3, 2, 8, 1, 4]));


// QUICK PROBLEM #5 //
// Your task is to return:
Expand All @@ -106,7 +146,7 @@ function isRubyComing(list) {
return list.some(e => e.language === 'Ruby');
}


console.log(isRubyComing(list1));



Expand Down
125 changes: 80 additions & 45 deletions 6-14_JS.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,115 @@
/*
// PROBLEM #1 //
You will be given an array of objects (associative arrays in PHP) representing data about developers
who have signed up to attend the next coding meetup that you are organising.

Your task is to return an object (associative array in PHP) which includes
the count of each coding language represented at the meetup.
// // PROBLEM #1 //
// You will be given an array of objects (associative arrays in PHP) representing data about developers
// who have signed up to attend the next coding meetup that you are organising.

// Your task is to return an object (associative array in PHP) which includes
// the count of each coding language represented at the meetup.

For example, given the following input array:
// For example, given the following input array:

var list1 = [
{ firstName: 'Noah', lastName: 'M.', country: 'Switzerland', continent: 'Europe', age: 19, language: 'C' },
{ firstName: 'Anna', lastName: 'R.', country: 'Liechtenstein', continent: 'Europe', age: 52, language: 'JavaScript' },
{ firstName: 'Ramon', lastName: 'R.', country: 'Paraguay', continent: 'Americas', age: 29, language: 'Ruby' },
{ firstName: 'George', lastName: 'B.', country: 'England', continent: 'Europe', age: 81, language: 'C' },
];
your function should return the following object (associative array in PHP):
// your function should return the following object (associative array in PHP):

{ C: 2, JavaScript: 1, Ruby: 1 }
*/
// { C: 2, JavaScript: 1, Ruby: 1 }

/*========================
ANSWER
=========================*/

const langObj = (arr) => {
const lang = {};
for (var i = 0; i < list1.length; i++) {
typeof lang[list1[i].language] === 'number' ? lang[list1[i].language]++ : lang[list1[i].language] = 1;
}
return lang;
}

console.log(langObj(list1));




/*
// PROBLEM #2 //
You will be given an array of objects representing data about developers who have signed up to attend
the next coding meetup that you are organising.

Given the following input array:
// // PROBLEM #2 //
// You will be given an array of objects representing data about developers who have signed up to attend
// the next coding meetup that you are organising.

// Given the following input array:

var list1 = [
{ firstName: 'Maria', lastName: 'Y.', country: 'Cyprus', continent: 'Europe', age: 30, language: 'Java' },
{ firstName: 'Victoria', lastName: 'T.', country: 'Puerto Rico', continent: 'Americas', age: 70, language: 'Python' },
];
write a function that returns the average age of developers (rounded to the nearest integer).
In the example above your function should return 50 (number).
// write a function that returns the average age of developers (rounded to the nearest integer).
// In the example above your function should return 50 (number).

Notes:
The input array will always be valid and formatted as in the example above.
Age is represented by a number which can be any positive integer.

*/
// Notes:
// The input array will always be valid and formatted as in the example above.
// Age is represented by a number which can be any positive integer.



const average = (arr) => {
var count = 0;
for(var i = 0; i < list1.length; i++) {
count += arr[i].age;
}
return Math.round(count/2);
}

console.log(average(list1));





/*
// PROBLEM #3 //
Given the following input array:
// Given the following input array:

var list1 = [
{ firstName: 'Emily', lastName: 'N.', country: 'Ireland', continent: 'Europe', age: 30, language: 'Ruby' },
{ firstName: 'Nor', lastName: 'E.', country: 'Malaysia', continent: 'Asia', age: 20, language: 'Clojure' }
];
write a function that adds the username property to each object in the input array:
// write a function that adds the username property to each object in the input array:

[
{ firstName: 'Emily', lastName: 'N.', country: 'Ireland', continent: 'Europe', age: 30, language: 'Ruby',
username: 'emilyn1990' },
{ firstName: 'Nor', lastName: 'E.', country: 'Malaysia', continent: 'Asia', age: 20, language: 'Clojure',
username: 'nore2000' }
]
The value of the username property is composed by concatenating:
// [
// { firstName: 'Emily', lastName: 'N.', country: 'Ireland', continent: 'Europe', age: 30, language: 'Ruby',
// username: 'emilyn1990' },
// { firstName: 'Nor', lastName: 'E.', country: 'Malaysia', continent: 'Asia', age: 20, language: 'Clojure',
// username: 'nore2000' }
// ]
// The value of the username property is composed by concatenating:

firstName in lower-case;
first letter of the lastName in lower-case; and
// firstName in lower-case;
// first letter of the lastName in lower-case; and

the birth year which for the purpose of this kata is calculated simply by subtracting age from the current year.
Please make sure that your function delivers the correct birth year irrespective of when it will be executed,
for example it should also work correctly for a meetup organised in 10-years-time.
The example above assumes that the function is run in year 2020.
// the birth year which for the purpose of this kata is calculated simply by subtracting age from the current year.
// Please make sure that your function delivers the correct birth year irrespecntive of whe it will be executed,
// for example it should also work correctly for a meetup organised in 10-years-time.
// The example above assumes that the function is run in year 2020.

Notes:
// Notes:

The input array will always be valid and formatted as in the example above.
Age is represented by a number which can be any positive integer.
Lastname will always be one upper-cased letter followed by dot, e.g. 'N.'
Order of the objects in the array should be maintained but order of the properties in the individual objects does not matter.
// The input array will always be valid and formatted as in the example above.
// Age is represented by a number which can be any positive integer.
// Lastname will always be one upper-cased letter followed by dot, e.g. 'N.'
// Order of the objects in the array should be maintained but order of the properties in the individual objects does not matter.

*/
const newArr = (arr) => {
for(var i = 0; i < arr.length; i++) {
arr[i].username = `${arr[i].firstName.toLowerCase()}${arr[i].lastName[0].toLowerCase()}${new Date().getFullYear()}`
}
return arr;

}

console.log(newArr(list1));



Expand All @@ -112,7 +134,20 @@ write a function that adds the username property to each object in the input arr
then sort it evens.sort((a,b) => a - b)
*/


sort = (nums) => {
const even = nums.filter( num => num % 2 == 0).sort((a,b) => a - b);
// nums.map((num) => num % 2 == 0 ? even.shift() : num);
nums.map((num) => {
if(num % 2 == 0) {
even.shift();
} else {
num;
}
});
return nums;
}

console.log(sort([5, 3, 2, 8, 1, 4]));



Expand Down
58 changes: 58 additions & 0 deletions 6-19(2).js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ numbers = [1,2,3]

function doublesAndIndex(nums) {
return nums.map(function (number,index){

return ((number * 2 ) * index);
})
}



// Put es6 version here:


const doublesAndIndex2 = (nums) => nums.map((number, index) => ((number * 2) * index));


console.log(doublesAndIndex2(numbers));


((number * 2 ) * index)
})
}
Expand All @@ -23,6 +39,7 @@ function doublesAndIndex(nums) {




// PROBLEM #2 //
//Given the following lists:

Expand All @@ -45,7 +62,11 @@ var list2 = [
{ firstName: 'Sumayah', lastName: 'M.', country: 'Tajikistan', continent: 'Asia', age: 30, language: 'CSS' },
{ firstName: 'Wichard', lastName: 'M.', country: 'America', continent: 'Europe', age: 30, language: 'JavaScript' },
{ firstName: 'Sumayah', lastName: 'M.', country: 'Europe', continent: 'Europe', age: 30, language: 'JavaScript' },

{ firstName: 'SongeBob', lastName: 'M.', country: 'Tajikistan', continent: 'Europe', age: 30, language: 'JavaScript' }

{ firstName: 'SpongeBob', lastName: 'M.', country: 'Tajikistan', continent: 'Europe', age: 30, language: 'JavaScript' }

];

// Your task is to return true if any of the JavaScript developers names start with R.
Expand All @@ -55,6 +76,20 @@ var list2 = [

function includesR(list){
return list.some( function(dev) {

return dev.firstName[0].includes('R') && dev.language.includes('JavaScript');
})
}

console.log(includesR(list1));


// Put es6 version here:

const includesR2 = (list) => list.some((dev) => dev.firstName[0].includes('R') && dev.language.includes('JavaScript'));

console.log(includesR2(list1));

return dev.firstName.includes('R')
})
}
Expand All @@ -68,13 +103,35 @@ function includesR(list){




// PROBLEM #3 //

// Write a function that loops through the numbers n down to 0. Bonus points for recursion.

function looper(n){
var i = n
while(i >= 0){

console.log(i);
i--
}

return 'Done';
}


// Put es6 version here:

const looper2 = (n) => {
while (n >= 0) {
console.log(n);
n--
}
return 'Done';
};

console.log(looper2(2));

console.log(i)
i--
}
Expand All @@ -90,6 +147,7 @@ function looper(n){




// Solutions will go here once we're all ready to see them: //


Expand Down