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..5895b7e 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,4 @@ -export function triangleArea(base, height) { +export function triangleArea(base, height) { + return (base * height) / 2; // your code here -} \ No newline at end of file +} diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..ef50539 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,6 @@ export function maxValue(values) { + if (values.length == 0) return 0; + return Math.max(...values); + // implementar logica aqui - -} \ No newline at end of file +} diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..869133e 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,16 @@ export function fibonacci(value) { + let soma = 0; + let anterior = 0; + let proximo = 1; + if (value == 1) { + return (soma = 1); + } + for (let i = 2; i <= value; i++) { + soma = anterior + proximo; + anterior = proximo; + proximo = soma; + } + return soma; + // implementar logica aqui - -} \ No newline at end of file +} diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..8c7c33d 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,8 @@ export function isPrime(value) { + for (let divisor = 2; divisor < value; divisor++) + if (value % divisor === 0) { + return false; + } + return true; // implementar logica aqui - -} \ No newline at end of file +} diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..8914608 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,8 @@ export function sum(values) { + let soma = 0; + for (let i = 0; i < values.length; i++) { + soma += values[i]; + } + return soma; // implementar logica aqui - -} \ No newline at end of file +} diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..998bbc0 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,10 @@ export function sumEven(value) { - // implementar logica aqui - -} \ No newline at end of file + let soma = 0; + for (let i = 0; i <= value.length; i++) { + if (value[i] % 2 === 0) { + soma += value[i]; + } + } + return soma; + // implementar logica aqui if (variavel % 2 !== 0) +} diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..c8f035d 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,6 @@ export function isAnagram(word1, word2) { + let str1 = word1.toLowerCase().split("").sort().join(""); + let str2 = word2.toLowerCase().split("").sort().join(""); + return str1 === str2; // implementar logica aqui - -} \ No newline at end of file +} diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..d165916 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,20 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" -} \ No newline at end of file + let freqCounter = []; + let textStr = text.toLowerCase(); + + for (let char of textStr) { + freqCounter[char] = freqCounter[char] + 1 || 1; + } + + let maxCount = 0; + let maxChar = null; + + for (let key in freqCounter) { + if (freqCounter[key] > maxCount) { + maxCount = freqCounter[key]; + maxChar = key; + } + } + // implementar logica aqui + return maxChar; +} diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..bf7fc1f 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,17 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + let longestWord = ""; + let longestWordsArray = []; + for (let i = 0; i < words.length; i++) { + if (words[i].length >= longestWord.length) { + longestWord = words[i]; + } + } + for (let i = 0; i < words.length; i++) { + if (words[i].length == longestWord.length) { + longestWordsArray.push(words[i]); + } + } + + return longestWordsArray; + // implementar logica aqui +}