diff --git a/01-greeting/index.js b/01-greeting/index.js index 8f551af..6b88803 100644 --- a/01-greeting/index.js +++ b/01-greeting/index.js @@ -1,4 +1,5 @@ export function greet(name) { // implementar logica aqui - return ""; + let resultadoNome = `Hello ${name}`; + return resultadoNome; } diff --git a/02-triangleArea/index.js b/02-triangleArea/index.js index 7628fcd..ace24c8 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,5 @@ export function triangleArea(base, height) { // your code here + let soma = base * height / 2 + return soma } \ No newline at end of file diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..8b8073a 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,8 @@ export function maxValue(values) { // implementar logica aqui - + let maiorNumero = Math.max(...values); + if (values.length === 0) { + return maiorNumero=0 + } else {}; + return maiorNumero ; } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..976c078 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,17 @@ export function fibonacci(value) { // implementar logica aqui - + let number1 = 0; + let number2 = 1; + let result; + + if (value === 0 || value === 1 ) { + return value; + } else { + for (let i = 1 ; i < value ; i++) { + result = number2 + number1; + number1 = number2; + number2 = result; + } + } + return result; } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..18936a8 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,9 @@ export function isPrime(value) { // implementar logica aqui - + for (let index = 2; index < value; index++) { + if (value % index === 0) { + 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..ca39303 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 index = 0; index < values.length; index++) { + soma += values[index]; + } + return soma; } \ No newline at end of file diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..6e14f98 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,10 @@ export function sumEven(value) { // implementar logica aqui - + var total = 0; + for (let i of value) { + if (i % 2 ===0) { + total += i; + } + } + return total; } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..e06ff3c 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,14 @@ export function isAnagram(word1, word2) { // implementar logica aqui - + if(word1 === word2) { + return true; + } else if (word1.length !== word2.length) { + return false; + } else { + var str1 = word1.toLowerCase().split("").sort().join(""); + var str2 = word2.toLowerCase().split("").sort().join(""); + var result = (str1 == str2); + return result; + } + } \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..52eb7de 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,22 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const boxChar = {}; + let max = 0; + let result = ''; + + for(let char of text){ + if(boxChar[char]){ + boxChar[char]++; + }else{ + boxChar[char] = 1; + } + } + for(let char in boxChar){ + if(boxChar[char] > max){ + max = boxChar[char]; + result = char; + } + } + + return result; } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..58b8a0f 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,17 @@ export function longestWords(words) { // implementar logica aqui - + + let loop = 0; + let newWords = []; + for (let index = 0; index < words.length; index++) { + if (words[index].length > loop) { + loop = words[index].length + } + } + for (let index = 0; index < words.length; index++) { + if (loop === words[index].length) { + newWords.push(words[index]) + } + } + return newWords; } \ No newline at end of file