Created
January 15, 2025 02:33
-
-
Save rogigs/33c0abccdf48159987216c3d6f1c0457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pergunta 1 | |
let INDICE = 13; | |
let SOMA = 0; | |
let K = 0; | |
while (K < INDICE) { | |
K = K + 1; | |
SOMA = SOMA + K; | |
} | |
console.log(SOMA); // Resultado: 91 | |
// Pergunta 2 | |
const number = 21; | |
const isFibonacci = (n) => { | |
const isLessThanZero = n < 0; | |
if (isLessThanZero) return false; | |
let a = 0; | |
let b = 1; | |
while (a <= n) { | |
if (a === n) return true; | |
[a, b] = [b, a + b]; | |
} | |
return false; | |
}; | |
isFibonacci(number) | |
? console.log(`\nThe number ${number} belongs to the Fibonacci sequence.`) | |
: console.log( | |
`\nThe number ${number} does NOT belong to the Fibonacci sequence.` | |
); | |
// Pergunta 3 | |
const getBilling = (() => { | |
const diaryBilling = [ | |
{ | |
dia: 1, | |
valor: 22174.1664, | |
}, | |
{ | |
dia: 2, | |
valor: 24537.6698, | |
}, | |
{ | |
dia: 3, | |
valor: 26139.6134, | |
}, | |
{ | |
dia: 4, | |
valor: 0.0, | |
}, | |
{ | |
dia: 5, | |
valor: 0.0, | |
}, | |
{ | |
dia: 6, | |
valor: 26742.6612, | |
}, | |
{ | |
dia: 7, | |
valor: 0.0, | |
}, | |
{ | |
dia: 8, | |
valor: 42889.2258, | |
}, | |
{ | |
dia: 9, | |
valor: 46251.174, | |
}, | |
{ | |
dia: 10, | |
valor: 11191.4722, | |
}, | |
{ | |
dia: 11, | |
valor: 0.0, | |
}, | |
{ | |
dia: 12, | |
valor: 0.0, | |
}, | |
{ | |
dia: 13, | |
valor: 3847.4823, | |
}, | |
{ | |
dia: 14, | |
valor: 373.7838, | |
}, | |
{ | |
dia: 15, | |
valor: 2659.7563, | |
}, | |
{ | |
dia: 16, | |
valor: 48924.2448, | |
}, | |
{ | |
dia: 17, | |
valor: 18419.2614, | |
}, | |
{ | |
dia: 18, | |
valor: 0.0, | |
}, | |
{ | |
dia: 19, | |
valor: 0.0, | |
}, | |
{ | |
dia: 20, | |
valor: 35240.1826, | |
}, | |
{ | |
dia: 21, | |
valor: 43829.1667, | |
}, | |
{ | |
dia: 22, | |
valor: 18235.6852, | |
}, | |
{ | |
dia: 23, | |
valor: 4355.0662, | |
}, | |
{ | |
dia: 24, | |
valor: 13327.1025, | |
}, | |
{ | |
dia: 25, | |
valor: 0.0, | |
}, | |
{ | |
dia: 26, | |
valor: 0.0, | |
}, | |
{ | |
dia: 27, | |
valor: 25681.8318, | |
}, | |
{ | |
dia: 28, | |
valor: 1718.1221, | |
}, | |
{ | |
dia: 29, | |
valor: 13220.495, | |
}, | |
{ | |
dia: 30, | |
valor: 8414.61, | |
}, | |
]; | |
const isWorkDay = (v) => v.valor !== 0; | |
const values = diaryBilling.filter(isWorkDay).map((v) => v.valor); | |
const minBilling = Math.min(...values); | |
const maxBilling = Math.max(...values); | |
const billingTotal = values.reduce((acc, curr) => acc + curr, 0); | |
const averageBilling = billingTotal / values.length; | |
const aboveAverageDays = diaryBilling.filter( | |
(v) => v.valor > averageBilling | |
).length; | |
console.log(`\nMenor valor de faturamento: R$ ${minBilling}`); | |
console.log(`Maior valor de faturamento: R$ ${maxBilling}`); | |
console.log( | |
`Número de dias com faturamento superior à média mensal: ${aboveAverageDays}` | |
); | |
})(); | |
// Pergunta 4 | |
const percentBilling = (() => { | |
const billings = { | |
SP: 67836.43, | |
RJ: 36678.66, | |
MG: 29229.88, | |
ES: 27165.48, | |
Others: 19849.53, | |
}; | |
const total = Object.values(billings).reduce((acc, valor) => acc + valor, 0); | |
console.log("\nPercentual de representação de cada estado:"); | |
Object.entries(billings).forEach(([state, value]) => { | |
const percent = ((value / total) * 100).toFixed(2); | |
console.log(`${state}: ${percent} %`); | |
}); | |
})(); | |
// Pergunta 5 | |
const reverseString = (() => { | |
const inputString = "reverse"; | |
let invertedString = ""; | |
for (let i = inputString.length - 1; i >= 0; i--) { | |
invertedString += inputString[i]; | |
} | |
console.log(`\n${invertedString}`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment