File tree Expand file tree Collapse file tree 2 files changed +73
-0
lines changed
1-EASY/JavaScript/1-inversing-a-string Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ # Challenge Description and Solution
2+
3+ ## English Version
4+
5+ ### Challenge Description
6+ Given a string, create a function that reverses it without using built-in reverse methods. This will help you practice loops and index handling.
7+
8+ ### Code Explanation
9+ The ` reverseString ` function iterates over the input string from the end to the beginning, concatenating characters to build the reversed string.
10+
11+ ### Relevant Code Snippet
12+
13+ ``` javascript
14+ function reverseString (s ) {
15+ let reversedStr = " " ;
16+ for (let i = s .length - 1 ; i >= 0 ; i-- ) {
17+ reversedStr += s[i];
18+ }
19+ return reversedStr;
20+ }
21+ ```
22+
23+ ### Example Usage
24+
25+ ``` javascript
26+ const testString = " hello" ;
27+ console .log (" Original string:" , testString);
28+ console .log (" Reversed string:" , reverseString (testString));
29+ ```
30+
31+ ---
32+
33+ ## Versión en Español
34+
35+ ### Descripción del Reto
36+ Dada una cadena, crea una función que la invierta sin usar métodos integrados de inversión. Esto te ayudará a practicar bucles y manejo de índices.
37+
38+ ### Explicación del Código
39+ La función ` reverseString ` itera sobre la cadena de entrada desde el final hasta el principio, concatenando caracteres para construir la cadena invertida.
40+
41+ ### Fragmento de Código Relevante
42+
43+ ``` javascript
44+ function reverseString (s ) {
45+ let reversedStr = " " ;
46+ for (let i = s .length - 1 ; i >= 0 ; i-- ) {
47+ reversedStr += s[i];
48+ }
49+ return reversedStr;
50+ }
51+ ```
52+
53+ ### Ejemplo de Uso
54+
55+ ``` javascript
56+ const testString = " hello" ;
57+ console .log (" Original string:" , testString);
58+ console .log (" Reversed string:" , reverseString (testString));
Original file line number Diff line number Diff line change 1+ // Challenge: Given a string, create a function that reverses it without using built-in reverse methods.
2+ // This will help you practice loops and index handling.
3+
4+ function reverseString ( s ) {
5+ let reversedStr = "" ;
6+ for ( let i = s . length - 1 ; i >= 0 ; i -- ) {
7+ reversedStr += s [ i ] ;
8+ }
9+ return reversedStr ;
10+ }
11+
12+ // Example usage
13+ const testString = "hello" ;
14+ console . log ( "Original string:" , testString ) ;
15+ console . log ( "Reversed string:" , reverseString ( testString ) ) ;
You can’t perform that action at this time.
0 commit comments