File tree Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change 17
17
- [x] [ Maximum Number of Balloons] ( ./src/hashing/maximum-number-of-balloons.ts )
18
18
- [x] [ Contiguous Array] ( ./src/hashing/contiguous-array.ts )
19
19
- [x] [ Ransom Note] ( ./src/hashing/ransom-note.ts )
20
- - [ ] [ Jewels and Stones] ( ./src/hashing/jewels-and-stones.ts )
20
+ - [x ] [ Jewels and Stones] ( ./src/hashing/jewels-and-stones.ts )
21
21
- [ ] [ Longest Substring Without Repeating Characters] ( ./src/hashing/longest-substring-without-repeating-characters.ts )
22
22
- [ ] Linked Lists
23
23
- [ ] [ Middle of the Linked List] ( ./src/linked-lists/middle-of-the-linked-list.ts )
Original file line number Diff line number Diff line change 1
- export function ( ) { }
1
+ export function numJewelsInStones ( jewels : string , stones : string ) : number {
2
+ const availableJews = new Set ( jewels ) ;
3
+
4
+ let totalJewels = 0 ;
5
+ for ( const stone of stones ) {
6
+ if ( availableJews . has ( stone ) ) {
7
+ totalJewels ++ ;
8
+ }
9
+ }
10
+
11
+ return totalJewels ;
12
+ }
Original file line number Diff line number Diff line change 1
- import { } from '@/hashing/jewels-and-stones.js' ;
1
+ import { numJewelsInStones } from '@/hashing/jewels-and-stones.js' ;
2
2
3
- describe . todo ( 'Hashing: Jewels and Stones' )
3
+ describe ( 'Hashing: Jewels and Stones' , ( ) => {
4
+ test . each ( [
5
+ {
6
+ jewels : 'aA' ,
7
+ stones : 'aAAbbbb' ,
8
+ output : 3 ,
9
+ } ,
10
+ {
11
+ jewels : 'z' ,
12
+ stones : 'ZZ' ,
13
+ output : 0 ,
14
+ } ,
15
+ {
16
+ jewels : 'k' ,
17
+ stones : 'abcD' ,
18
+ output : 0 ,
19
+ } ,
20
+ ] ) (
21
+ 'numJewelsInStones($jewels, $stones) === $output' ,
22
+ ( { jewels, stones, output } ) => {
23
+ expect ( numJewelsInStones ( jewels , stones ) ) . toStrictEqual ( output ) ;
24
+ }
25
+ ) ;
26
+ } ) ;
You can’t perform that action at this time.
0 commit comments