File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import { assertEquals } from 'https://deno.land/std@0.203.0/assert/assert_equals.ts' ;
2+ import reverseString from './reverse_string.ts' ;
3+
4+ Deno . test (
5+ 'Reverse a string.' ,
6+ async ( test ) => {
7+ await test . step ( {
8+ name : 'Empty string' ,
9+ fn : ( ) => {
10+ assertEquals (
11+ reverseString ( '' ) ,
12+ '' ,
13+ ) ;
14+ } ,
15+ } ) ;
16+
17+ await test . step ( {
18+ name : 'Normal string' ,
19+ fn : ( ) => {
20+ assertEquals (
21+ reverseString ( 'abc' ) ,
22+ 'cba' ,
23+ ) ;
24+ } ,
25+ } ) ;
26+ } ,
27+ ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * This function reverses a string.
3+ *
4+ * @param inputString The string to reverse
5+ * @returns The reversed string
6+ */
7+ export default function reverseString ( inputString : string ) : string {
8+ if ( ! inputString || inputString . length === 1 ) {
9+ return inputString ;
10+ }
11+ return inputString . split ( '' ) . reverse ( ) . join ( '' ) ;
12+ }
You can’t perform that action at this time.
0 commit comments