Minimum Index Sum of Two Lists Lab

Easy
48
1
51.4% Acceptance

In this coding lab, you will be implementing a function to find the common strings with the least index sum from two arrays of strings, list1 and list2. A common string is a string that appears in both list1 and list2. You must return all the common strings with the least index sum in any order.

The primary objective of this lab is to evaluate your problem-solving skills and ability to work with arrays, strings, and index manipulations in JavaScript. You'll also demonstrate your knowledge of ESM import/export concepts.

Lab Requirements

To complete this lab, you need to implement the findRestaurant function. The parameters and expected return value of the function are as follows:

/** * @param {string[]} list1 * @param {string[]} list2 * @return {string[]} */ var findRestaurant = function(list1, list2) { };

This function takes two arrays of strings, list1 and list2, and returns an array of strings containing the common strings with the least index sum. You should use ESM import/export throughout your code.

Examples

Consider the following examples:

Example 1:

let list1 = ["Shogun","Tapioca Express","Burger King","KFC"]; let list2 = ["Piatti","The Grill at Torrey Pines","Hungry Hunter Steakhouse","Shogun"]; findRestaurant(list1, list2);

Output: ["Shogun"]

Explanation: The only common string is "Shogun".

Example 2:

let list1 = ["Shogun","Tapioca Express","Burger King","KFC"]; let list2 = ["KFC","Shogun","Burger King"]; findRestaurant(list1, list2);

Output: ["Shogun"]

Explanation: The common string with the least index sum is "Shogun" with index sum = (0 + 1) = 1.

Example 3:

let list1 = ["happy","sad","good"]; let list2 = ["sad","happy","good"]; findRestaurant(list1, list2);

Output: ["sad","happy"]

Explanation: There are three common strings: "happy" with index sum = (0 + 1) = 1, "sad" with index sum = (1 + 0) = 1, and "good" with index sum = (2 + 2) = 4. The strings with the least index sum are "sad" and "happy".

Make sure to export the findRestaurant function so it can be used in the evaluation script.

NOTE: Make sure you're using default export on the function