-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1018.js
More file actions
33 lines (24 loc) · 899 Bytes
/
1018.js
File metadata and controls
33 lines (24 loc) · 899 Bytes
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
export function problem (lines) {
const valorTotal = lines[0]
const notasDisponiveis = [100, 50, 20, 10, 5, 2, 1]
function quantidadeNotas (valor, nota){
const quantidade = Math.floor(valor / nota)
return quantidade
}
function quantidadesPorNota (valor, notas) {
const listaNotas = notas.map( nota => {
const quantidade = quantidadeNotas(valor, nota)
valor = valor - (quantidade * nota)
return {nota, quantidade}
})
return listaNotas
}
function mostrarNotasNecessarias (valor, notas) {
const notasNecessarias = quantidadesPorNota(valor, notas)
console.log (valor)
notasNecessarias.forEach( ({quantidade, nota}) => {
console.log (`${quantidade} nota(s) de R$ ${nota},00`)
} )
}
mostrarNotasNecessarias(valorTotal, notasDisponiveis)
}