File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed
src/fcc-intermediate-algorithms
tests/fcc-intermediate-algorithms Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ From the Freecodecamp Javascript Certification Intermediate Algorithms module
12
12
- [ Pig Latin] ( #pig-latin )
13
13
- [ Search and Replace] ( #search-and-replace )
14
14
- [ DNA Pairing] ( #dna-pairing )
15
+ - [ Missing Letters] ( #missing-letters )
15
16
16
17
#### Sum All Numbers In a Range
17
18
@@ -174,3 +175,26 @@ export function pairElements(str) {
174
175
return pairs;
175
176
}
176
177
```
178
+
179
+ #### Missing Letters
180
+
181
+ Find the missing letter in the passed letter range and return it.
182
+
183
+ If all letters are present in the range, return undefined.
184
+
185
+ ``` javascript
186
+ export function fearNotLetter (str ) {
187
+ if ((str .charCodeAt (str .length - 1 ) - str .charCodeAt (0 )) + 1 === str .length ) {
188
+ return undefined ;
189
+ }
190
+
191
+ for (let i = 0 ; i < str .length - 1 ; i++ ) {
192
+ const currentCharCode = str .charCodeAt (i);
193
+ if (currentCharCode + 1 !== str .charCodeAt (i + 1 )) {
194
+ return String .fromCharCode (currentCharCode + 1 );
195
+ }
196
+ }
197
+
198
+ return undefined ;
199
+ }
200
+ ```
Original file line number Diff line number Diff line change
1
+ export function fearNotLetter ( str ) {
2
+ if ( ( str . charCodeAt ( str . length - 1 ) - str . charCodeAt ( 0 ) ) + 1 === str . length ) {
3
+ return undefined ;
4
+ }
5
+
6
+ for ( let i = 0 ; i < str . length - 1 ; i ++ ) {
7
+ const currentCharCode = str . charCodeAt ( i ) ;
8
+ if ( currentCharCode + 1 !== str . charCodeAt ( i + 1 ) ) {
9
+ return String . fromCharCode ( currentCharCode + 1 ) ;
10
+ }
11
+ }
12
+
13
+ return undefined ;
14
+ }
Original file line number Diff line number Diff line change
1
+ import { fearNotLetter } from "../../src/fcc-intermediate-algorithms/missing_letters" ;
2
+
3
+ test ( 'should find missing character' , ( ) => {
4
+ expect ( fearNotLetter ( "abcdefghjklmno" ) ) . toBe ( "i" ) ;
5
+ expect ( fearNotLetter ( "abcdefghijklmnopqrstuvwxyz" ) ) . toBe ( undefined ) ;
6
+ } ) ;
You can’t perform that action at this time.
0 commit comments