Skip to content

Commit

Permalink
175th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Jul 21, 2024
1 parent 4fe99cd commit 0c52a55
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { findWordsContaining } from './findWordsContaining';

describe('2942. Find Words Containing Character', () => {
test('findWordsContaining', () => {
expect(findWordsContaining(['leet', 'code'], 'e')).toStrictEqual([0, 1]);
expect(findWordsContaining(['abc', 'bcd', 'aaaa', 'cbc'], 'a')).toStrictEqual([0, 2]);
expect(findWordsContaining(['abc', 'bcd', 'aaaa', 'cbc'], 'z')).toStrictEqual([]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type FindWordsContaining = (words: string[], x: string) => number[];

/**
* Accepted
*/
export const findWordsContaining: FindWordsContaining = (words, x) => {
const result: number[] = [];

for (let i = 0; i < words.length; i++) {
if (words[i].includes(x)) {
result.push(i);
}
}

return result;
};

0 comments on commit 0c52a55

Please sign in to comment.