Remove Enemies from the List

Imagine you're managing a guest list for a party, and you've realized that some people on the list are not welcome (enemies). Your task is to remove all occurrences of these enemies from the guest list to ensure a peaceful event.

Instructions:

  • Write a function named removeEnemies that takes two arrays as input:

    • The first array, people, contains the names of people on the guest list.

    • The second array, enemies, contains the names of people who should be removed from the guest list.

  • The function should return a new array that includes only the people who are not enemies.

Note: Only use the map, filter, or reduce methods, or a combination of these methods, to solve the problem. Do not use loops to iterate or perform the operation.

Example 1

Input: removeEnemies(["Alice", "Bob", "Charlie"], ["Charlie"]);
Output: ["Alice", "Bob"]

Example 2

Input: removeEnemies(["John", "Jane", "John", "Doe"], ["John"]);
Output: ["Jane", "Doe"]

Example 3

Input: removeEnemies(["Anna", "Elsa", "Olaf"], ["Hans"]);
Output: ["Anna", "Elsa", "Olaf"]

Are you stuck on this problem?

Get detailed, step-by-step solution and improve your JavaScript skills.

  • Detailed Explanation: Each solution comes with a comprehensive explanation, helping you understand the logic and concepts thoroughly.
  • Learn to Write Better Code: Even if you have written the code, discover ways to improve it and adopt best practices.
  • Save Time: Don’t waste hours struggling—get the solution and learn efficiently.
  • Lifetime Access: Get access to lifetime solutions for all problems available
Get the Solution

" I struggled with this problem for hours, but the solution provided here was clear and easy to follow. It helped me understand where I went wrong and improved my coding skills significantly." - Jane D.

If you're not satisfied, I offer a 7-day money-back guarantee.