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..c09415e 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..2136361 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,8 @@ export function maxValue(values) { // implementar logica aqui - + let maxV = Math.max(...values); + if(!values.length){ + maxV = 0; + } + return maxV; } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..fbd62d0 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,13 @@ export function fibonacci(value) { // implementar logica aqui - + let first = 0; + let second = 1; + if (value <= 1) { + return value; + } + for(let i = 3; i <= value; i++){ + second = first + second; + first = second - first; + } + return first + second; } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..d3d70d2 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,9 @@ export function isPrime(value) { // implementar logica aqui - + for (let x = 2; x < value; x++) { + if (value % x === 0 || value <= 1) { + return false; + } + } + return true; } \ No newline at end of file diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..911b188 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 = 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..962ef5c 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; +} diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..8bec24f 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,4 @@ export function isAnagram(word1, word2) { // implementar logica aqui - + return (word1.toLowerCase().split('').sort().join('')) === (word2.toLowerCase().split('').sort().join('')) } \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..bedc121 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,16 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const textObj = {} + let maxCount = 0 + let mostUsedChar = "" + for (let char of text) { + textObj[char] = textObj[char] + 1 || 1 + } + for (let key in textObj) { + if (textObj[key] > maxCount) { + maxCount = textObj[key] + mostUsedChar = key + } + } + return mostUsedChar } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..b07a2f3 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,16 @@ export function longestWords(words) { // implementar logica aqui - + let long = 0; + let longWords = []; + for(let i = 0;i < words.length;i++){ + if(words[i].length >= long){ + long = words[i].length; + } + } + for(let j = 0;j < words.length;j++){ + if(words[j].length == long){ + longWords.push(words[j]); + } + } + return longWords; } \ No newline at end of file