Write a function getPeopleBornIn which takes in an array and string month, and returns a new array of people and their birthday information who were all born in the given month.
function getPeopleBornIn(staff, month) { for (var i = 0; i < staff.length; i++) { if (staff[i].birthDay.month === month) { var filteredInfo = staff[i]; } } return `${filteredInfo.name.first} ${filteredInfo.name.last}: ${filteredInfo.birthDay.month} ${filteredInfo.birthDay.day}, ${filteredInfo.birthDay.year}`; } 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}} ]; console.log(getPeopleBornIn(staff, 'August')); //output: ["Ben Bitdiddle: August 19, 1984", "Lem Tweakit: August 11, 1989"]
https://stackoverflow.com/questions/66575484/why-am-i-returning-only-one-of-the-filtered-objects-instead-of-all-of-them March 11, 2021 at 10:04AM
没有评论:
发表评论