How can this problem be solved?

  • 0
    Help find a robot using the searchRobot function. It takes a robot object, and an array of all the workPlaces we know of that the robot might be currently in. The result of the search and rescue operation should be the name of the place where the robot is now.

    First I tried to iterate over the array and then the objects. What else can you solve?

    Examples:

    const robot = {
      name: 'Sundar',
    };
    const workPlaces = [
      {
        name: 'mate academy',
        staff: ['Roma', 'Misha', 'Yura'],
      },
      {
        name: 'Google',
        staff: ['Larry', 'Sergey', 'Sundar'],
      },
    ];


    searchRobot (robot, workPlaces) // returns 'Google';
    JavaScript Abigail O'Brien, Mar 12, 2019

  • 1 Answers
  • 0
    First I tried to iterate over the array and then the objects.


    And where is the code?



    const result = workPlaces.find((obj) => obj.staff.includes(robot.name));
    return result?.name;
    Dominick Williamson

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!