diff --git a/01-greeting/index.js b/01-greeting/index.js index 8f551af..5c0279c 100644 --- a/01-greeting/index.js +++ b/01-greeting/index.js @@ -1,4 +1,4 @@ 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..53067fe 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,4 @@ 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..5187e63 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,8 @@ export function maxValue(values) { // implementar logica aqui - + if(values.length === 0){ + return 0 + } else { + return Math.max(...values) + } } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..73e275e 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,25 @@ export function fibonacci(value) { // implementar logica aqui - + if(value < 1) return 0 + if(value <=2) return 1 + let fibMin2 = 0 + let fibMin1 = 1 + let fibValue = value + for(let i = 2; i <= value; i++) { + fibValue = fibMin1 + fibMin2 + fibMin2 = fibMin1 + fibMin1 = fibValue + } + return fibValue + +// Forma inicial pensada, mas demorava muito tempo para passar nos testes. + + // if(value === 0) { + // return 0 + // } + // else if (value <= 2) { + // return 1 + // } + // return fibonacci(value - 1) + fibonacci(value - 2); + } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..805d2b6 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,6 @@ export function isPrime(value) { // implementar logica aqui - + var start = 2; + while (start <= Math.sqrt(value)) if (value % start++ < 1) return false; + return value > 1; } \ No newline at end of file diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..dc904a4 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,8 @@ export function sum(values) { // implementar logica aqui - + let soma = 0 + for(let i in values) { + 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..b17535e 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,11 @@ export function sumEven(value) { // implementar logica aqui - -} \ No newline at end of file + var retorno = value.filter(pares => (pares %2)== 0); + let soma = 0 + for(let i in retorno) { + soma += retorno[i] + } + return soma +} + + diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..1361c11 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,13 @@ export function isAnagram(word1, word2) { // implementar logica aqui - -} \ No newline at end of file + let word1Lower = word1.toLowerCase() + let word2Lower = word2.toLowerCase() + if (word1Lower.length !== word2Lower.length) { + return false; +} +var string1 = word1Lower.split('').sort().join(''); +var string2 = word2Lower.split('').sort().join(''); + +var result = (string1 === string2); +return result; +} diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..e95466a 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,11 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" + let max = 0, + maxChar = ''; + text.split('').forEach(function(char){ + if(text.split(char).length > max) { + max = text.split(char).length; + maxChar = char; + } + }); + return maxChar; } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..5a0b288 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,11 @@ export function longestWords(words) { // implementar logica aqui - -} \ No newline at end of file + let longest = ''; + for (let word of words) { + if (word.length > longest.length) { + longest = word; + } + } + + return words.filter((word) => word.length === longest.length); + }