@@ -109,17 +109,12 @@ for (let index = 0; index < message.length; index++) {
109
109
const reverseManual = ( word ) => word . split ( "" ) . reverse ( ) . join ( "" )
110
110
111
111
/**
112
- * Determine if two words are palindromes, anagram or isogram
113
- * @param {string } firstWord Any string word
114
- * @param {string } secondWord Any string word
115
- * @returns Returns a boolean response true or false
112
+ * Extrae las palabras únicas de un string
113
+ * @param {string } word Any string word
116
114
*/
117
- function textAnalizer ( firstWord , secondWord ) {
118
- //TODO
119
- if ( palindromeTester ( firstWord , secondWord ) ) console . log ( "Las palabras son palíndromes" )
120
-
121
- const resultAnagram = anagramaTester ( firstWord , secondWord )
122
- const resultIsogram = isogramaTester ( firstWord , secondWord )
115
+ const palabrasUnicas = ( word ) => {
116
+ //TODO al string realizar .split agregarlo a un Set retornarlo a string y si es igual no tiene palabras repetidas
117
+ return Array . from ( new Set ( word . split ( "" ) ) ) . join ( "" )
123
118
}
124
119
125
120
/**
@@ -134,17 +129,58 @@ const palindromeTester = (firstWord, secondWord) => {
134
129
}
135
130
136
131
/**
137
- * Determine if two words are anagram
132
+ * Determine if a word is an isogram
133
+ * @param {string } word Any string word
134
+ * @returns {boolean } Returns true if the word is an isogram, false otherwise
135
+ */
136
+ const esIsograma = ( word ) => {
137
+ return word === palabrasUnicas ( word )
138
+ }
139
+
140
+ /**
141
+ * Determine if two words are isograms
138
142
* @param {string } firstWord Any string word
139
143
* @param {string } secondWord Any string word
140
- * @returns Returns a boolean response true or false
144
+ * @returns { boolean } Returns true if both words are isograms, false otherwise
141
145
*/
142
- const anagramaTester = ( firstWord , secondWord ) => { }
146
+ const isogramaTester = ( firstWord , secondWord ) => {
147
+ const firstIsIsogram = esIsograma ( firstWord )
148
+ const secondIsIsogram = esIsograma ( secondWord )
149
+
150
+ console . log ( `La palabra ${ firstWord } ${ firstIsIsogram ? "es" : "no es" } un isograma` )
151
+ console . log ( `La palabra ${ secondWord } ${ secondIsIsogram ? "es" : "no es" } un isograma` )
152
+
153
+ return firstIsIsogram && secondIsIsogram
154
+ }
143
155
144
156
/**
145
- * Determine if two words are isogram
157
+ * Determine if two words are anagrams
146
158
* @param {string } firstWord Any string word
147
159
* @param {string } secondWord Any string word
148
- * @returns Returns a boolean response true or false
160
+ * @returns { boolean } Returns true if both words are anagrams, false otherwise
149
161
*/
150
- const isogramaTester = ( firstWord , secondWord ) => { }
162
+ const anagramaTester = ( firstWord , secondWord ) => {
163
+ const normalize = ( word ) => word . toLowerCase ( ) . replace ( / \s + / g, "" ) . split ( "" ) . sort ( ) . join ( "" )
164
+ return normalize ( firstWord ) === normalize ( secondWord )
165
+ }
166
+
167
+ function textAnalizer ( firstWord , secondWord ) {
168
+ const firstIsIsogram = esIsograma ( firstWord )
169
+ const secondIsIsogram = esIsograma ( secondWord )
170
+
171
+ if ( palindromeTester ( firstWord , secondWord ) ) {
172
+ console . log ( "Las palabras son palíndromes" )
173
+ } else {
174
+ console . log ( "Las palabras no son palíndromes" )
175
+ }
176
+
177
+ if ( anagramaTester ( firstWord , secondWord ) ) {
178
+ console . log ( "Las palabras son anagramas" )
179
+ } else {
180
+ console . log ( "Las palabras no son anagramas" )
181
+ }
182
+ console . log ( `La palabra ${ firstWord } ${ firstIsIsogram ? "es" : "no es" } un isograma` )
183
+ console . log ( `La palabra ${ secondWord } ${ secondIsIsogram ? "es" : "no es" } un isograma` )
184
+ }
185
+
186
+ textAnalizer ( "Listen" , "silent" )
0 commit comments