forked from Laboratoria/DEV013-text-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzer.js
More file actions
65 lines (61 loc) · 2.23 KB
/
Copy pathanalyzer.js
File metadata and controls
65 lines (61 loc) · 2.23 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
const analyzer = {
getWordCount: (text) => {
const palabras = text;
const arrpalabras = palabras.trim().split(" ");
return arrpalabras.length;
//TODO: esta función debe retornar el recuento de palabras que se encuentran en el parámetro `text` de tipo `string`.
},
getCharacterCount: (text) => {
const caracteres = text;
const arrcaracteres = caracteres.split("");
return arrcaracteres.length;
//TODO: esta función debe retornar el recuento de caracteres que se encuentran en el parámetro `text` de tipo `string`.
},
getCharacterCountExcludingSpaces: (text) => {
const excluir = text;
const espacios = excluir
.trim()
.replace(/[^\w\s]|_/g, "")
.replace(/\s+/g, "");
return espacios.length;
//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) => {
const array = text.split(" ");
let suma = 0;
for (let i = 0; i < array.length; i++) {
suma += array[i].length;
}
const promedio = suma / array.length;
return Math.round(promedio * 100) / 100;
//TODO: esta función debe retornar la longitud media de palabras que se encuentran en el parámetro `text` de tipo `string`.
},
getNumberCount: (text) => {
//const arrayNum = text.match(/\b\d+(\.\d+)?\b/g);
//return arrayNum ? arrayNum.length : 0;
const arrayNum = text.split(" ");
let contador = 0;
for (let i = 0; i < arrayNum.length; i++) {
const arrayIn = arrayNum[i].replace(/\.$/, "");
if (!isNaN(arrayIn) && arrayIn !== "") {
contador++;
}
}
return contador;
//TODO: esta función debe retornar cúantos números se encuentran en el parámetro `text` de tipo `string`.
},
getNumberSum: (text) => {
const array = text.match(/\b\d+(\.\d+)?\b/g);
let suma = 0;
if (array === null) {
return 0;
} else {
suma = array.reduce((sum, num) => {
return sum + parseFloat(num);
}, 0);
return suma;
}
//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;