development #11

Merged
luizfelipe9627 merged 20 commits from development into master 2022-11-02 13:01:51 +00:00
10 changed files with 73 additions and 5 deletions

View File

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

View File

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

View File

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

View File

@ -1,4 +1,17 @@
export function fibonacci(value) { export function fibonacci(value) {
// implementar logica aqui // implementar logica aqui
if(value < 1) return 0;
if(value <= 2) return 1;
let valorFib1 = 1;
let valorFib2 = 0;
let valorFibonacci = value;
for(let i = 2; i <= value; i++) {
valorFibonacci = valorFib1 + valorFib2;
valorFib2 = valorFib1;
valorFib1 = valorFibonacci;
}
return valorFibonacci;
} }

View File

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

View File

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

View File

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

View File

@ -1,4 +1,8 @@
export function isAnagram(word1, word2) { export function isAnagram(word1, word2) {
// implementar logica aqui // implementar logica aqui
let array1 = word1.toLowerCase().split('').sort();
let array2 = word2.toLowerCase().split('').sort();
if(array1.join() === array2.join()) return true;
else return false;
} }

View File

@ -1,4 +1,21 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui // implementar logica aqui
return "" let array = [];
let stringText = text.toLowerCase();
let letrasJuntas = stringText.replace(/ /g, '');
for(let i = 0; i < letrasJuntas.length; i++) {
let letra = letrasJuntas.charAt(i);
if(array[letra] != undefined) array[letra]++
else array[letra] = 1;
}
let letrasOrdenadas = Object.keys(array).sort(function order(key1, key2) {
if(array[key1] > array[key2]) return -1;
else if(array[key1] < array[key2]) return +1;
else return 0;
})[0];
return letrasOrdenadas;
} }

View File

@ -1,4 +1,16 @@
export function longestWords(words) { export function longestWords(words) {
// implementar logica aqui // implementar logica aqui
const longestWords = words.sort(
(a, b) => {return b.length - a.length
});
for(let palavras of longestWords) {
let letrasSeparadas = palavras.split('');
if(letrasSeparadas.length === 8) return longestWords.slice(0, 1);
else if(letrasSeparadas.length === 4) return longestWords.slice(0, 2);
else return longestWords.slice(0, 3);
}
return longestWords;
} }