Created
May 24, 2025 16:28
-
-
Save tatsuyax25/0e1d0f5b4316d16ba0adf77fe6cd783b to your computer and use it in GitHub Desktop.
You are given a 0-indexed array of strings words and a character x. Return an array of indices representing the words that contain the character x. Note that the returned array may be in any order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string[]} words | |
* @param {character} x | |
* @return {number[]} | |
*/ | |
var findWordsContaining = function(words, x) { | |
const indices = []; // Array to store indices of words containing 'x' | |
// Iterate through each word in the 'words' array | |
for (let i = 0; i < words.length; i++) { | |
if (words[i].includes(x)) { // Check if the word contains the target character | |
indices.push(i); // Store the index if condition is met | |
} | |
} | |
return indices; // Return the array of indices | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment