Skip to content

Activity 15: Create Your Own AI Guide!

The instructions are provide in the worksheet:

Supplemental Material

Part 1: wordMultiple

The following problem text is taken from the CodingBat: wordMultiple exercise.

wordMultiple

Given an array of strings, return a Map where each different string is a key and its value is true if that string appears 2 or more times in the array.

wordMultiple(["a", "b", "a", "c", "b"]) → {"a": true, "b": true, "c": false}

wordMultiple(["c", "b", "a"]) → {"a": false, "b": false, "c": false}

Part 2: wordMultiplePositions

Here is a slightly more difficult variation on the previous problem:

wordMultiplePositions

Given an array of strings, return a Map> where each key is a string that appears 2 or more times in the array, and its value is the list of all indices where that string occurs.

wordMultiplePositions(["a", "b", "a", "c", "b"]) → {"a": [0, 2], "b": [1, 4]}

wordMultiplePositions(["c", "b", "a"]) → {}

wordMultiplePositions(["c", "c", "c", "c"]) → {"c": [0, 1, 2, 3]}

An online IDE is provided for you to test your code: OneCompiler: wordMultiplePositions.