Coding Meetup 2 Flashcards

1
Q

Prepare the count of languages

Return an object which includes the count of each coding language represented at the meetup.

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' },
];

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

function countLanguages(list) {
  // thank you for checking out the Coding Meetup kata :)
}
A
//Create new variable, empty object for count.
//For every dev of list 
//Assign new variable to dev.language
//if count hasOwnProperty of language add 1 to the count
//else create new key of that language value 1
//at the end of loop, return obj count
let count = {};
  for (let dev of list) {
    let lang = [dev.language];
    if (count.hasOwnProperty(lang)) {
      count[lang]++;
    } else {
      count[lang] = 1;
    }
  }
  return count;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Find the most senior developer

Return a sequence which includes the developer who is the oldest. In case of a tie, include all same-age senior developers listed in the same order as they appeared in the original input array.

var list1 = [
  { firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language: 'PHP' },
  { firstName: 'Odval', lastName: 'F.', country: 'Mongolia', continent: 'Asia', age: 38, language: 'Python' },
  { firstName: 'Emilija', lastName: 'S.', country: 'Lithuania', continent: 'Europe', age: 19, language: 'Python' },
  { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' },
];

[
{ firstName: ‘Gabriel’, lastName: ‘X.’, country: ‘Monaco’, continent: ‘Europe’, age: 49, language: ‘PHP’ },
{ firstName: ‘Sou’, lastName: ‘B.’, country: ‘Japan’, continent: ‘Asia’, age: 49, language: ‘PHP’ },
]

function findSenior(list) {
  // thank you for checking out the Coding Meetup kata 
}
A
//new variable empty arr for ages
//for each dev push ages into arr
//return filter if age equals max of age arr

let ageArr=[];
list.forEach(dev=>ageArr.push(dev.age));
return list.filter( dev=> dev.age === Math.max(…ageArr) ) ;

//New variable for maxAge, value of  max of mapped developer's age
//return filter if age equals maxAge
let maxAge = Math.max(...list.map(dev => dev.age))
  return list.filter(dev => dev.age === maxAge);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Will all continents be represented?

Return:

true if all of the following continents / geographic zones will be represented by at least one developer: ‘Africa’, ‘Americas’, ‘Asia’, ‘Europe’, ‘Oceania’.
false otherwise.

var list1 = [
  { firstName: 'Fatima', lastName: 'A.', country: 'Algeria', continent: 'Africa', age: 25, language: 'JavaScript' },
  { firstName: 'Agustín', lastName: 'M.', country: 'Chile', continent: 'Americas', age: 37, language: 'C' },
  { firstName: 'Jing', lastName: 'X.', country: 'China', continent: 'Asia', age: 39, language: 'Ruby' },
  { firstName: 'Laia', lastName: 'P.', country: 'Andorra', continent: 'Europe', age: 55, language: 'Ruby' },
  { firstName: 'Oliver', lastName: 'Q.', country: 'Australia', continent: 'Oceania', age: 65, language: 'PHP' },
];
A
//new variable array of continents
//for each cont of continents 
//if  (list some dev.continent equals cont) is false 
return false
//else finish loop and return true
 let continents = ['Africa', 'Americas', 'Asia', 'Europe', 'Oceania'];
  for (let cont of continents) {
    if (!list.some(dev => dev.continent === cont)){
      return false;
    }
  }
  return true;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Is the meetup age-diverse?

Return:

true if developers from all of the following age groups have signed up: teens, twenties, thirties, forties, fifties, sixties, seventies, eighties, nineties, centenarian (at least 100 years young).

false otherwise.

function isAgeDiverse(list) {
  // thank you for checking out the Coding Meetup kata 
}
A
//new variable array of arrays of Ages groups
//for each group of ageGroups :
//if some developers age isn't in the age range
//return false
//else finish running loop
//then return true
 let ageGroups = [[1, 19], [20, 29], [30, 39], [40, 49], [50, 59], [60, 69], [70, 79], [80, 89], [90, 99], [100, 200]]
  for (let group of ageGroups) {
    if (!list.some(dev => dev.age >= group[0] && dev.age <= group[1])) {
      return false;
    }
  }
  return true;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Create usernames

write a function that adds the username property to each object in the 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' }
];

[
{ 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
  • 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.
A
// return map of list:
//create dev.username equal to:
//return dev.
 return list.map(dev => {
    dev.username = dev.firstName.toLowerCase() + dev.lastName[0].toLowerCase() + (new Date().getFullYear() - dev.age);
    return dev;
  })
//forEACH
//return list
  list.forEach(dev => {
    let name = dev.firstName.toLowerCase() + dev.lastName[0].toLowerCase();
    let year = new Date().getFullYear() - dev.age;
    dev.username = name + year;

})
return list;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Find the average age

write a function that returns the average age of developers (rounded to the nearest integer)

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' },
];
function getAverageAge(list) {
  // thank you for checking out the Coding Meetup kata :)
}
A

return Math.round (list.reduce((acc,dev)=> acc + dev.age,0)/ list.length)

////
let ages =list.map(dev=>dev.age) return Math.round(ages.reduce((acc,age)=> acc + age,0) / ages.length);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Find GitHub admins

write a function that when executed as findAdmin(list1, ‘JavaScript’) returns only the JavaScript developers who are GitHub admins:

var list1 = [
  { firstName: 'Harry', lastName: 'K.', country: 'Brazil', continent: 'Americas', age: 22, language: 'JavaScript', githubAdmin: 'yes' },
  { firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 49, language: 'Ruby', githubAdmin: 'no' },
  { firstName: 'Jing', lastName: 'X.', country: 'China', continent: 'Asia', age: 34, language: 'JavaScript', githubAdmin: 'yes' },
  { firstName: 'Piotr', lastName: 'B.', country: 'Poland', continent: 'Europe', age: 128, language: 'JavaScript', githubAdmin: 'no' }
];

[
{ firstName: ‘Harry’, lastName: ‘K.’, country: ‘Brazil’, continent: ‘Americas’, age: 22, language: ‘JavaScript’, githubAdmin: ‘yes’ },
{ firstName: ‘Jing’, lastName: ‘X.’, country: ‘China’, continent: ‘Asia’, age: 34, language: ‘JavaScript’, githubAdmin: ‘yes’ }
]

function findAdmin(list, lang) {
  // thank you for checking out the Coding Meetup 
}
A

return list.filter(dev=>dev.language === lang && dev.githubAdmin === ‘yes’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is the meetup language-diverse?

Return either:

true if the number of meetup participants representing any of the three programming languages is ** at most 2 times higher than the number of developers representing any of the remaining programming languages**; or
false otherwise.

var list1 = [
  { firstName: 'Daniel', lastName: 'J.', country: 'Aruba', continent: 'Americas', age: 42, language: 'Python' },
  { firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 22, language: 'Ruby' },
  { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 43, language: 'Ruby' },
  { firstName: 'Hanna', lastName: 'L.', country: 'Hungary', continent: 'Europe', age: 95, language: 'JavaScript' },
  { firstName: 'Jayden', lastName: 'P.', country: 'Jamaica', continent: 'Americas', age: 18, language: 'JavaScript' },
  { firstName: 'Joao', lastName: 'D.', country: 'Portugal', continent: 'Europe', age: 25, language: 'JavaScript' }
];
function isLanguageDiverse(list) {
  // thank you for checking out the Coding Meetup kata :)
}
A
//new variable empty obj for count
//for  dev in list :
//new variable for dev.lang
//if count has property of lang  add 1 count.lang ++ 
//else create property with value of 1 countl.lang=1
//variable min value of min of values from obj count
//if max is bigger than min *2 return false
//else return true
  let count = {};
  for (let dev of list) {
    let lang = [dev.language];
    if (count.hasOwnProperty(lang)) {
      count[lang]++;
    } else {
      count[lang] = 1;
    }
  }
  let min = Math.min(...Object.values(count))
  let max = Math.max(...Object.values(count))

if (max > min * 2) {
return false;
}

return true;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Order the food

Return an object which includes the count of food options selected by the developers on the meetup sign-up form..

{ vegetarian: 2, standard: 1, vegan: 1 }

var list1 = [
  { firstName: 'Noah', lastName: 'M.', country: 'Switzerland', continent: 'Europe', age: 19, language: 'C', 
    meal: 'vegetarian' },
  { firstName: 'Anna', lastName: 'R.', country: 'Liechtenstein', continent: 'Europe', age: 52, language: 'JavaScript', 
    meal: 'standard' },
  { firstName: 'Ramona', lastName: 'R.', country: 'Paraguay', continent: 'Americas', age: 29, language: 'Ruby', 
    meal: 'vegan' },
  { firstName: 'George', lastName: 'B.', country: 'England', continent: 'Europe', age: 81, language: 'C', 
    meal: 'vegetarian' },
];
function orderFood(list) {
  // thank you for checking out the Coding Meetup kata :)
}
A
//new variable order empty obj 
//for dev of list:
//new variable value of dev.meal
//if order has property of meal add 1
//else create property with value of 1
//return order
let order={};
  for(let dev of list){
    let meal=dev.meal;
    if(order.hasOwnProperty(meal)){
      order[meal] ++;
    } else{
      order[meal]=1;
    }
  }
  return order;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Find the odd names

Return only the developers where if you add the ASCII representation of all characters in their first names, the result will be an odd number:

[
{ firstName: ‘Abb’, lastName: ‘O.’, country: ‘Israel’, continent: ‘Asia’, age: 39, language: ‘Java’ }
]

var list1 = [
  { firstName: 'Aba', lastName: 'N.', country: 'Ghana', continent: 'Africa', age: 21, language: 'Python' },
  { firstName: 'Abb', lastName: 'O.', country: 'Israel', continent: 'Asia', age: 39, language: 'Java' }
];
function findOddNames(list) {
  // thank you for checking out the Coding Meetup kata :)
}
A
//return filter list
//return  dev.firstName.
//split
//reduce converting each letter into code
// if this %2 is different from 0 

return list.filter(dev=>{
return dev.firstName.split(‘’).reduce((acc,lttr)=>acc + lttr.charCodeAt(0),0) %2 !== 0
})

//New variable empty array for oddNames
//For each developer calculate ascii count:
//new variable value of dev.firstName
//split name 
//map chartCode of every letter
//reduce to calculate sum of ascii code
//if sum of code % 2 is something else than 0 then push into addNames arr
//return oddNames arr
let oddNames=[];
  list.forEach(dev=>{
    let name = dev.firstName
    let asciiCount=name.split('').map(lttr=>lttr.charCodeAt(0)).reduce((acc,code)=>acc+code);
    console.log(asciiCount)
    if(asciiCount %2 !== 0){
      oddNames.push(dev);
    }
  })
  return oddNames;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Ask for missing details

Write a function that

Adds the question property to each object in the input array where the developer has not provided the relevant details (marked with a null value). The value of the question property should be the following string:

Hi, could you please provide your .

And returns only the developers with missing details:

[
{ firstName: null, lastName: ‘I.’, country: ‘Argentina’, continent: ‘Americas’, age: 35, language: ‘Java’,
question: ‘Hi, could you please provide your firstName.’ },
{ firstName: ‘Lukas’, lastName: ‘X.’, country: ‘Croatia’, continent: ‘Europe’, age: 35, language: null,
question: ‘Hi, could you please provide your language.’ }
]

var list1 = [
  { firstName: null, lastName: 'I.', country: 'Argentina', continent: 'Americas', age: 35, language: 'Java' },
  { firstName: 'Lukas', lastName: 'X.', country: 'Croatia', continent: 'Europe', age: 35, language: null },
  { firstName: 'Madison', lastName: 'U.', country: 'United States', continent: 'Americas', age: 32, language: 'Ruby' } 
];
function askForMissingDetails(list) {
  // thank you for checking out the Coding Meetup kata :)
}
A
//For each developer 
//& for each property of developer
//if property has value of null then create a property of question in that developer
// filter developer that have property of question
 list.forEach(dev=>{
    for(let prop in dev){
      if (dev[prop] === null){
        dev.question = `Hi, could you please provide your ${prop}.`
      }
    }
  })
  return list.filter(dev=>dev.hasOwnProperty('question'))
return list.filter(dev=>{
  for(let prop in dev){
    if(dev[prop]== null){
      dev.question=`Hi, could you please provide your ${prop}.`;
      return dev;
    }
  }
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly