-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fe99cd
commit 0c52a55
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/page-27/2942. Find Words Containing Character/findWordsContaining.test.ts
This file contains 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
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([]); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
src/page-27/2942. Find Words Containing Character/findWordsContaining.ts
This file contains 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
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; | ||
}; |