File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1313
1414// You will need to come up with an appropriate name for the function
1515// Use the string documentation to help you find a solution
16+
17+
18+
19+ // ================== Strings in UpperCase =====================
20+
21+ function convertUpperCaseString ( str ) {
22+ let UPPER_SNAKE_CASE = "" ;
23+ // console.log(typeof str);
24+
25+ for ( let i = 0 ; i < str . length ; i ++ ) {
26+ if ( str [ i ] === " " ) {
27+ UPPER_SNAKE_CASE += "_" ;
28+ } else UPPER_SNAKE_CASE += str [ i ] . toUpperCase ( ) ; ;
29+ }
30+
31+ return UPPER_SNAKE_CASE ;
32+ }
33+
34+ console . log ( convertUpperCaseString ( "hola there" ) ) ;
35+
36+ // ================ First letter capitalized ===================
37+
38+
39+ function firstLetterCapitalized1 ( str ) {
40+ let result = "" ;
41+ for ( let i = 0 ; i < str . length ; i ++ ) {
42+ if ( i === 0 || str [ i - 1 ] === " " ) {
43+ result += str [ i ] . toUpperCase ( ) ;
44+ } else {
45+ result += str [ i ] ;
46+ }
47+ }
48+ return result ;
49+ }
50+
51+ console . log ( firstLetterCapitalized1 ( "first letter capitalized" ) ) ;
52+
53+
54+ // ================ Last letter capitalized ===================
55+
56+ let quote = 'He said, "It\'s a sunny day!"' ;
57+
58+ function lastLetterCapitalized ( str ) {
59+ let result = "" ;
60+
61+ for ( let i = 0 ; i < str . length ; i ++ ) {
62+ if ( str [ i + 1 ] === " " || i === str . length - 1 ) {
63+ result += str [ i ] . toUpperCase ( ) ;
64+ } else {
65+ result += str [ i ] ;
66+ }
67+ }
68+
69+ return result ;
70+ }
71+
72+ console . log ( lastLetterCapitalized ( `hola there ${ quote } ` ) ) ;
73+
74+
You can’t perform that action at this time.
0 commit comments