forked from rbk-org/rbk-toy-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathW4D5.js
33 lines (25 loc) · 1.12 KB
/
W4D5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
1-Write a function called getPeopleBornIn that takes an array and string month,
and returns a new array of people and their birthday information who were all born in the given month.
A sample input array would look like:
var staff = [
{name: {first: "Alyssa", last: "Hacker"}, birthDay: {month: "June", day: 5, year: 1987}},
{name: {first: "Ben", last: "Bitdiddle"}, birthDay: {month: "August", day: 19, year: 1984}},
{name: {first: "Eva", last: "Ator"}, birthDay: {month: "March", day: 29, year: 1980}},
{name: {first: "Lem", last: "Tweakit"}, birthDay: {month: "August", day: 11, year: 1989}},
{name: {first: "Louis", last: "Reasoner"}, birthDay: {month: "November", day: 17, year: 1992}}
];
A call to your function getPeopleBornIn(staff, 'August');
Would return:
["Ben Bitdiddle: August 19, 1984", "Lem Tweakit: August 11, 1989"]
*/
function getPeopleBornIn(array,str){
var y=[];
var e="";
for(var t=0;t<array.length;t++){
if(array[t].birthDay.month===str){
e=array[t].name.first+' '+array[t].name.last+': '+array[t].birthDay.month+' '+array[t].birthDay.day+', '+array[t].birthDay.year;
y.push(e)
}e=''
}return y
}