-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathsolved.js
More file actions
53 lines (45 loc) · 1.27 KB
/
solved.js
File metadata and controls
53 lines (45 loc) · 1.27 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
function buscarNotaPorId(notas, id) {
return notas.find(nota => nota.id === id);
}
function buscarNotaPorTituloExacto(notas, titulo) {
return notas.find(nota => nota.title === titulo);
}
function filtrarNotasPorCategoria(notas, categoria) {
return notas.filter(nota => nota.category === categoria);
}
function filtrarNotasPorLongitudMinima(notas, longitudMinima) {
return notas.filter(nota => nota.content.length >= longitudMinima);
}
function sumarIds(notas) {
return notas.reduce((acc, nota) => acc + nota.id, 0);
}
function concatenarTitulos(notas) {
return notas.reduce((acc, nota, index) => {
if (index === 0) {
return nota.title;
}
return acc + "-" + nota.title;
}, "");
}
function contarNotasPorCategoria(notas) {
return notas.reduce((acc, nota) => {
const categoria = nota.category;
acc[categoria] = (acc[categoria] || 0) + 1;
return acc;
}, {});
}
function calcularPromedioDeIds(notas) {
if (notas.length === 0) return 0;
const suma = notas.reduce((acc, nota) => acc + nota.id, 0);
return suma / notas.length;
}
module.exports = {
buscarNotaPorId,
buscarNotaPorTituloExacto,
filtrarNotasPorCategoria,
filtrarNotasPorLongitudMinima,
sumarIds,
concatenarTitulos,
contarNotasPorCategoria,
calcularPromedioDeIds,
};