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..60b1284 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,4 @@ export function triangleArea(base, height) { // your code here -} \ No newline at end of file + return base * height / 2; +} \ No newline at end of file diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..4443a3c 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,5 @@ -export function maxValue(values) { +export function maxValue(values = []) { // implementar logica aqui - + if (values.length < 1) return 0 + return Math.max(...values) } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..bd05558 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,12 @@ export function fibonacci(value) { // implementar logica aqui - + let n1 = 0 + let n2 = 1 + let temp + for (let i = 0; i < value; i++) { + temp = n1 + n1 = n1 + n2 + n2 = temp + } + return n1 } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..0c09d66 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,9 @@ export function isPrime(value) { - // implementar logica aqui - +// implementar logica aqui + for (let i = 2; i < value; i++) { + if (value % i === 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..24d86ca 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,6 @@ export function sum(values) { // implementar logica aqui - + return values.reduce((somaTotal, numeroAtual) => { + return somaTotal + numeroAtual + },0) } \ No newline at end of file diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..3259657 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,6 @@ export function sumEven(value) { // implementar logica aqui - + return value.reduce((somaTotal, numeroAtual) => { + return numeroAtual % 2 == 0 ? somaTotal + numeroAtual : somaTotal + },0) } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..788a365 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..d1a9a80 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,18 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let count = 0; + let char = " "; + let save = {}; + text.split("").forEach((letter) => { + if(save[letter]){ + save[letter] += 1; + } else { + save[letter] = 1; + } + if(save[letter] > count){ + count = save[letter]; + char = letter; + } + }) + return char; } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..336f209 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,9 @@ export function longestWords(words) { // implementar logica aqui - + return words.reduce((longWords, currentWord) => { + if(!longWords[0] || longWords[0].length < currentWord.length) return [currentWord]; + if(longWords[0].length > currentWord.length) return longWords; + longWords.push(currentWord); + return longWords; + },[]) } \ No newline at end of file