Merge pull request 'feature/algoritmos' (#1) from feature/algoritmos into master

Reviewed-on: #1
This commit is contained in:
Cainã Milech 2022-10-29 19:58:08 +00:00
commit 9206482aee
10 changed files with 86 additions and 15 deletions

View File

@ -1,4 +1,3 @@
export function greet(name) { export function greet(name) {
// implementar logica aqui return `Hello ${name}`;
return "";
} }

View File

@ -1,3 +1,3 @@
export function triangleArea(base, height) { export function triangleArea(base, height) {
// your code here return base * height /2;
} }

View File

@ -1,4 +1,6 @@
export function maxValue(values) { export function maxValue(values) {
// implementar logica aqui if(values.length === 0){
return 0;
}
return Math.max.apply(null, values);
} }

View File

@ -1,4 +1,16 @@
export function fibonacci(value) { export function fibonacci(value) {
// implementar logica aqui
let soma = 0;
let resultado = 0;
let proximo = 1;
for(let i = 0; i < value; i++){
soma = resultado + proximo;
resultado = proximo;
proximo = soma;
}
return resultado;
} }

View File

@ -1,4 +1,12 @@
export function isPrime(value) { export function isPrime(value) {
// implementar logica aqui
if(value === 1){
return false;
} for(let divisor = 2; divisor < value; divisor++){
if(value % divisor === 0){
return false;
}
} return true;
} }

View File

@ -1,4 +1,9 @@
export function sum(values) { export function sum(values) {
// implementar logica aqui
let total = 0;
for(let i = 0; i < values.length; i++){
total += values[i];
} return total;
} }

View File

@ -1,4 +1,11 @@
export function sumEven(value) { export function sumEven(value) {
// implementar logica aqui
let total = 0;
for(let i = 0; i < value.length; i++){
if(value[i] % 2 === 0){
total += value[i];
}
} return total;
} }

View File

@ -1,4 +1,8 @@
export function isAnagram(word1, word2) { export function isAnagram(word1, word2) {
// implementar logica aqui
let palavra1 = word1.toLowerCase().split('').sort().join('');
let palavra2 = word2.toLowerCase().split('').sort().join('');
return (palavra1 === palavra2);
} }

View File

@ -1,4 +1,20 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui
return "" const objeto = {};
let repeticoes = 0;
let maisRepetida = '';
for(let i of text){
objeto[i] = objeto[i] +1 || 1;
}
for(let i in objeto){
if(objeto[i] > repeticoes){
repeticoes = objeto[i];
maisRepetida = i;
}
}
return maisRepetida;
} }

View File

@ -1,4 +1,22 @@
export function longestWords(words) { export function longestWords(words) {
// implementar logica aqui
let maior = '';
let maiores = [];
for(let palavra of words){
if(palavra.length > maior.length){
maior = palavra;
}
}
let caracteres = maior.length;
for(let palavra of words){
if(caracteres === palavra.length){
maiores.push(palavra);
}
}
return maiores;
} }