diff --git a/01-greeting/index.js b/01-greeting/index.js index 8f551af..021dae1 100644 --- a/01-greeting/index.js +++ b/01-greeting/index.js @@ -1,4 +1,3 @@ export function greet(name) { - // implementar logica aqui - return ""; + return `Hello ${name}`; } diff --git a/02-triangleArea/index.js b/02-triangleArea/index.js index 7628fcd..a1251e8 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,4 @@ export function triangleArea(base, height) { - // your code here + let area = (base*height)/2; + return area; } \ No newline at end of file diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..e1aa3b2 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,17 @@ export function maxValue(values) { - // implementar logica aqui - + let maiorValor = values[0]; + + if(values.length === 0) { + maiorValor = 0; + }else { + for(let i = 0 ; i < values.length ; i++) { + let valor = values[i]; + + if(valor > maiorValor) { + maiorValor = valor; + } + } + } + + return maiorValor; } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..a203513 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,16 @@ export function fibonacci(value) { - // implementar logica aqui - + if(value == 0) return 0; + if(value == 1 || value == 2) return 1; + + let fib; + let valorAnterior1 = 0; + let valorAnterior2 = 1; + + for(let i = 2 ; i <= value ; i++) { + fib = valorAnterior1 + valorAnterior2; + valorAnterior1 = valorAnterior2; + valorAnterior2 = fib; + } + + return fib; } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..8732d02 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,11 @@ 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; } \ No newline at end of file diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..8bab285 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,9 @@ export function sum(values) { - // implementar logica aqui - + let soma = 0; + + for(let i = 0 ; i < values.length ; i++) { + soma += values[i]; + } + + return soma; } \ No newline at end of file diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..1336edc 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,11 @@ export function sumEven(value) { - // implementar logica aqui - + let somaPares = 0; + + for(let i = 0 ; i < value.length ; i++) { + if(value[i] % 2 == 0){ + somaPares += value[i]; + } + } + + return somaPares; } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..93fc628 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,18 @@ export function isAnagram(word1, word2) { - // implementar logica aqui + let anagram; + + if(word1.length !== word2.length) { + anagram = false; + } + + let palavra1 = word1.toLowerCase().split("").sort().join(""); + let palavra2 = word2.toLowerCase().split("").sort().join(""); + + if(palavra1 === palavra2) { + anagram = true; + }else { + anagram = false; + } + return anagram; } \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..c9f7abc 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,27 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" + let texto = text.toLowerCase().replace(/ /g, "").split("").sort(); + let letras = []; + let contadorLetras = 0; + let letrasRepetidas = []; + + for(let i = 0 ; i < texto.length ; i++) { + if(texto[i + 1] === texto[i]) { + contadorLetras++; + }else { + letras.push(texto[i]); + letrasRepetidas.push(contadorLetras); + contadorLetras = 1; + } + } + + let valorMaximoLetras = Math.max(...letrasRepetidas); + let letraMaisRepetida = ""; + + for(let i = 0 ; i < letrasRepetidas.length ; i++) { + if(letrasRepetidas[i] == valorMaximoLetras) { + letraMaisRepetida = letras[i]; + } + } + + return letraMaisRepetida; } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..f5b5a48 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,13 @@ export function longestWords(words) { - // implementar logica aqui - + let palavrasMaisLongas = [""]; + + for(let palavra of words) { + if(palavra.length > palavrasMaisLongas[0].length) { + palavrasMaisLongas = [palavra]; + }else if(palavra.length === palavrasMaisLongas[0].length) { + palavrasMaisLongas.push(palavra); + } + } + + return palavrasMaisLongas; } \ No newline at end of file