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..eafab7e 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,3 @@ export function triangleArea(base, height) { - // your code here + return base * height /2; } \ No newline at end of file diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..9dc5fea 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,6 @@ export function maxValue(values) { - // implementar logica aqui - + if(values.length === 0){ + return 0; + } + return Math.max.apply(null, values); } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..11de2c9 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,16 @@ 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; } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..f77634f 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,12 @@ 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..90ffdd5 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,9 @@ export function sum(values) { - // implementar logica aqui + + let total = 0; + + for(let i = 0; i < values.length; i++){ + total += values[i]; + } return total; } \ No newline at end of file diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..615012b 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,11 @@ 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; } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..f0be87a 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,8 @@ 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); + } \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..252e917 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,20 @@ 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; + } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..edaa5ec 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,22 @@ 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; } \ No newline at end of file