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..00121cc 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) { // your code here -} \ No newline at end of file + return (base * height) / 2; +} diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..93d537a 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,12 @@ export function maxValue(values) { // implementar logica aqui - -} \ No newline at end of file + let max = values.reduce(function (a, b) { + return Math.max(a, b); + }, -Infinity); + + if (values.length === 0) { + return 0; + } else { + return max; + } +} diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..b32d40a 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,8 @@ export function fibonacci(value) { // implementar logica aqui - -} \ No newline at end of file + let arr = [0, 1]; + for (let i = 2; i < value + 1; i++) { + arr.push(arr[i - 2] + arr[i - 1]); + } + return arr[value]; +} diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..740d231 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,8 @@ export function isPrime(value) { // implementar logica aqui - -} \ No newline at end of file + for (let i = 2; i < value; i++) + if (value % i === 0) { + return false; + } + return value > 1; +} diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..9cd7e9c 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,5 @@ export function sum(values) { // implementar logica aqui - -} \ No newline at end of file + let sum = values.reduce((sum, number) => sum + number, 0); + return sum; +} diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..ac5407e 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,15 @@ export function sumEven(value) { // implementar logica aqui - -} \ No newline at end of file + let pair = (x) => x % 2 === 0; + + if (value.length === 0) { + return 0; + } else if (value % 2 === 1) { + return 0; + } else { + let sumOfPairs = value + .filter(pair) + .reduce((pairs, number) => pairs + number); + return sumOfPairs; + } +} diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..241bc1f 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,11 @@ export function isAnagram(word1, word2) { // implementar logica aqui - -} \ No newline at end of file + let str1 = word1.toLowerCase().split("").sort().join(""); + let str2 = word2.toLowerCase().split("").sort().join(""); + + if (str1 === str2) { + return true; + } else { + return false; + } +} diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..14b4a30 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,17 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" -} \ No newline at end of file + // implementar logica aqui + let arr = text.toLowerCase().split("").sort(); + let mostRepeated = null; + let moreOccurrences = -1; + + let count = 1; + for (let i = 1; i <= arr.length; i++) { + if (i < arr.length && arr[i] === arr[i - count]) { + count++; + } else if (count > moreOccurrences) { + mostRepeated = arr[i - 1]; + moreOccurrences = count; + } + } + return `${mostRepeated}`; +} diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..f18a6d4 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,5 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + // implementar logica aqui + let maxLength = Math.max(...words.map((e) => e.length)); + return words.filter((e) => e.length === maxLength); +}