File tree Expand file tree Collapse file tree 7 files changed +56
-5
lines changed
Expand file tree Collapse file tree 7 files changed +56
-5
lines changed Original file line number Diff line number Diff line change 1+ export function coolDown ( str : string ) : string | null {
2+ if ( typeof str !== "string" ) {
3+ return null ;
4+ }
5+
6+ let i = 0 ;
7+ let result = "" ;
8+
9+ while ( str [ i ] !== undefined ) {
10+ result += String . fromCharCode (
11+ ( str . charCodeAt ( i ) > 64 && str . charCodeAt ( i ) < 91 ) ||
12+ ( str . charCodeAt ( i ) > 191 && str . charCodeAt ( i ) < 224 )
13+ ? str . charCodeAt ( i ) + 32
14+ : str . charCodeAt ( i )
15+ ) ;
16+ i ++ ;
17+ }
18+
19+ return result ;
20+ }
Original file line number Diff line number Diff line change 1111 * froth(123); // Returns null
1212 * ```
1313 */
14- export function froth ( str : string ) {
14+ export function froth ( str : string ) : string | null {
1515 if ( typeof str !== "string" ) {
1616 return null ;
1717 }
@@ -21,7 +21,8 @@ export function froth(str: string) {
2121
2222 while ( str [ i ] !== undefined ) {
2323 result += String . fromCharCode (
24- str . charCodeAt ( i ) > 96 && str . charCodeAt ( i ) < 123
24+ ( str . charCodeAt ( i ) > 96 && str . charCodeAt ( i ) < 123 ) ||
25+ ( str . charCodeAt ( i ) > 223 && str . charCodeAt ( i ) < 256 )
2526 ? str . charCodeAt ( i ) - 32
2627 : str . charCodeAt ( i )
2728 ) ;
Original file line number Diff line number Diff line change 1616 * ```
1717 */
1818
19- export function hasMilk ( str : string , word : string ) {
19+ export function hasMilk ( str : string , word : string ) : boolean | null {
2020 if ( typeof str !== "string" || typeof word !== "string" ) {
2121 return null ;
2222 }
Original file line number Diff line number Diff line change 11export { brewLength } from "./brewLength" ;
22export { compareBeans } from "./compareBeans" ;
3+ export { coolDown } from "./coolDown" ;
34export { findFirstSip } from "./findFirstSip" ;
45export { findFlavor } from "./findFlavor" ;
56export { froth } from "./froth" ;
Original file line number Diff line number Diff line change 1111 * pourCoffee(123); // Returns null
1212 * ```
1313 */
14- export function pourCoffee ( str : string ) {
14+ export function pourCoffee ( str : string ) : string | null {
1515 if ( typeof str !== "string" ) {
1616 return null ;
1717 }
Original file line number Diff line number Diff line change 1+ import { coolDown } from "../src/index" ;
2+
3+ test ( "coolDown should return string in lowercase" , ( ) => {
4+ expect ( coolDown ( "COFFEE" ) ) . toBe ( "coffee" ) ;
5+ expect ( coolDown ( "cOfFeE" ) ) . toBe ( "coffee" ) ;
6+ } ) ;
7+
8+ test ( "coolDown should return string with extended Latin alphabets in lowercase" , ( ) => {
9+ expect ( coolDown ( "ÄÖÅ" ) ) . toBe ( "äöå" ) ;
10+ } ) ;
11+
12+ test ( "coolDown should not return a string containing uppercase letters" , ( ) => {
13+ expect ( coolDown ( "coffee" ) ) . not . toBe ( "COFFEE" ) ;
14+ expect ( coolDown ( "COFFEE" ) ) . not . toBe ( "COFFEE" ) ;
15+ expect ( coolDown ( "cOfFeE" ) ) . not . toBe ( "COFFEE" ) ;
16+ } ) ;
17+
18+ test ( "coolDown should return null for non strings" , ( ) => {
19+ expect ( coolDown ( 0 as any ) ) . toBeNull ( ) ;
20+ expect ( coolDown ( true as any ) ) . toBeNull ( ) ;
21+ expect ( coolDown ( { } as any ) ) . toBeNull ( ) ;
22+ expect ( coolDown ( [ ] as any ) ) . toBeNull ( ) ;
23+ expect ( coolDown ( undefined as any ) ) . toBeNull ( ) ;
24+ expect ( coolDown ( null as any ) ) . toBeNull ( ) ;
25+ } ) ;
Original file line number Diff line number Diff line change 11import { froth } from "../src/index" ;
22
3- test ( "froth to return string in uppercase" , ( ) => {
3+ test ( "froth should return string in uppercase" , ( ) => {
44 expect ( froth ( "coffee" ) ) . toBe ( "COFFEE" ) ;
55 expect ( froth ( "cOfFeE" ) ) . toBe ( "COFFEE" ) ;
66} ) ;
77
8+ test ( "froth should return string with extended Latin alphabets in uppercase" , ( ) => {
9+ expect ( froth ( "äöå" ) ) . toBe ( "ÄÖÅ" ) ;
10+ } ) ;
11+
812test ( "froth should not return a string containing lowercase letters" , ( ) => {
913 expect ( froth ( "coffee" ) ) . not . toBe ( "coffee" ) ;
1014 expect ( froth ( "COFFEE" ) ) . not . toBe ( "coffee" ) ;
You can’t perform that action at this time.
0 commit comments