JSFiddle - React, Tailwind, and code Playground

by lavisha99

JavaScript

let directory = [{
    firstName: 'jose',
    lastName: 'Lee',
    address: {
      street: 'lk',
      suburb: 'dhf'
    }
  },
  {
    firstName: 'kose',
    lastName: 'kee',
    address: {
      street: 'lk',
      suburb: 'dhf'
    }
  }
]
console.log(directory);
//The first function receives as parameters a string query and a staff member object. The function should return true if either the first name or last name of the staff member starts with the string query. Otherwise, the function should return false.
function search(stringQuery, staffMember) {
  for (i = 0; i < directory.length; i++) {
    if (directory[i].firstName.startsWith(stringQuery) || directory[i].lastName.startsWith(stringQuery)) {
      return true
    } else {
      return false
    }
    }
}
console.log(search('k', directory));
//The second function should receive a staff member object as a parameter and return a single string containing all the information of the staff member. For example, "Jose Ortiz. Address: 15 Reid Road, New Lynn, Auckland." 

function staffInfo(staffMember) {
console.log(staffMember.firstName+' '+ staffMember.lastName+' Address: '+ staffMember.address);
}
staffInfo(directory[0]);
/*Narrative: Now, you will combine the two functions created in problem 2 to search a query string in the entire directory. This function should receive as a parameter a query string and nothing else. The function should return an array of strings where each string represents a staff member whose name matched the query string according to the criteria of your basic search function of problem 2.

It is advisable to test your functions using console.log.

Constraints:

You must name this function searchPeople and must receive only one parameter, the query string. 
*/
function