diff --git a/01-greeting/index.js b/01-greeting/index.js index 8f551af..4bef4b0 100644 --- a/01-greeting/index.js +++ b/01-greeting/index.js @@ -1,4 +1,5 @@ export function greet(name) { // implementar logica aqui - return ""; + const frase = `Hello ${name}`; + return frase; } diff --git a/02-triangleArea/index.js b/02-triangleArea/index.js index 7628fcd..5fedc42 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,5 @@ export function triangleArea(base, height) { // your code here + const area = (base * height) / 2; + return area; } \ No newline at end of file diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..e357a27 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,9 @@ export function maxValue(values) { // implementar logica aqui - + if (values.length < 1) { + return 0; + } + const maior = Math.max(...values); + + return maior; } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..455d010 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,13 @@ export function fibonacci(value) { // implementar logica aqui - + if (value <= 1) { + return value; + } + + let arr = [0, 1]; + + for (let i = 2; i < value + 1; i++) { + arr[i] = arr[i - 2] + arr[i - 1]; + } + return arr[value]; } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..6f72492 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,22 @@ export function isPrime(value) { // implementar logica aqui - + let totalDivisores = 0; + + for (let i = 1; i <= value; i++) { + if (value % i == 0) { + totalDivisores++ + } + } + + if (totalDivisores == 2) { + return true; + } else return false + + if (value === 2) { + return true; + } + + if (value === 1) { + return false; + } } \ 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..4759c1f 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,11 @@ export function sumEven(value) { // implementar logica aqui - + let soma = 0; + + for (let i = 0; i < value.length; i++) { + if (value[i] % 2 == 0) { + soma += value[i]; + } + } + return soma; } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..7dd2b77 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,13 @@ export function isAnagram(word1, word2) { // implementar logica aqui - + let array = word1.toLowerCase().split('').sort(); + let array2 = word2.toLowerCase().split('').sort(); + + if (word1.length !== word2.length) { + return false; + } else { + if (array.toString() === array2.toString()) { + return true; + } else return false; + } } \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..12c72d9 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,15 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const value = text.toLocaleLowerCase().split("").sort(); + + let counts = {}; + value.forEach(function (x) { + counts[x] = (counts[x] || 0) + 1; + }); + + const maior = Object.keys(counts).sort(function (a, b) { + return counts[a] > counts[b] ? -1 : counts[b] > counts[a] ? 1 : 0; + })[0]; + + return maior; } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..08aaea9 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,13 @@ export function longestWords(words) { // implementar logica aqui - + let maior = ""; + + for (const string of words) { + if (string.length > maior.length) { + maior = string; + } + } + const maiores = words.filter((string) => string.length === maior.length); + + return maiores; } \ No newline at end of file