-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzer.js
More file actions
85 lines (71 loc) · 2.45 KB
/
analyzer.js
File metadata and controls
85 lines (71 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const analyzer = {
getWordCount: (text) => {
if (text === '') {
return 0;
}
const cadenaDeTexto = text.trim().split(' ').length /*excluir signos*/
return cadenaDeTexto
},
getCharacterCount: (text) => {
if (text === '') {
return 0;
}
return text.length
//TODO: esta función debe retornar el recuento de caracteres que se encuentran en el parámetro `text` de tipo `string`.
},
getCharacterCountExcludingSpaces: (text) => {
if (text === '') {
return 0;
}
const caracSinEspacios = text.replace(/[\s.,/#!$%^&*;:{}=\-_~()]/g, '').length
return caracSinEspacios
//TODO: esta función debe retornar el recuento de caracteres excluyendo espacios y signos de puntuación que se encuentran en el parámetro `text` de tipo `string`.
},
getAverageWordLength: (text) => {
if (text === '') {
return 0;
}
const arrayWord = text.trim().split(' ')
//console.log (arrayWord)
let contador = 0
for (let i = 0; i < arrayWord.length; i++) {
//console.log (arrayWord[i].length)
contador = contador + arrayWord[i].length
}
const conversion = contador/arrayWord.length
//console.log (conversion)
return Number(conversion.toFixed(2))
//TODO: esta función debe retornar la longitud media de palabras que se encuentran en el parámetro `text` de tipo `string`.
},
getNumberCount: (text) => {
if (text === '') {
return 0;
}
//PRUEBA 1
const numSinSignos = text.match(/(?<!\w)\d+(\.\d+)?(?!\w)/g)
return numSinSignos ? numSinSignos.length : 0;
//PRUEBA 3
/*for (let i = 0; i < text.trim().split(' ').length; i++) {
let num = text
let numero = parseInt(text)
}
return numero*/
//PRUEBA 2
/*if (parseInt(text)){
return text.length
} else {
return ''
}*/
//TODO: esta función debe retornar cúantos números se encuentran en el parámetro `text` de tipo `string`.
},
getNumberSum: (text) => {
if (text === '') {
return 0;
}
const sumaNum = text.match(/(?<!\w)\d+(\.\d+)?(?!\w)/g)
return sumaNum ? sumaNum.reduce((anterior, actual) => anterior + parseFloat(actual), 0) : 0;
//return sumaNum ? sumaNum.length : 0;
//TODO: esta función debe retornar la suma de todos los números que se encuentran en el parámetro `text` de tipo `string`.
},
};
export default analyzer;