From 28b2daec0b53d4aa6176362ccdd8c69fa2ceb03d Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 08:00:42 -0300 Subject: [PATCH 01/11] feat/solucao greeting --- 01-greeting/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}`; } -- 2.34.1 From 2f2efc8ebee9aa9ccdc7a9bdc2981b4b038984b6 Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 08:05:57 -0300 Subject: [PATCH 02/11] feat: solucao triangleArea --- 02-triangleArea/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; +} -- 2.34.1 From e6a9ae42a39d3a33020ddd14b4faf769626100ec Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 08:30:15 -0300 Subject: [PATCH 03/11] feat: solucao maxValue --- 03-maxValue/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..a78ce0f 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,8 @@ export function maxValue(values) { // implementar logica aqui - -} \ No newline at end of file + if (values.length === 0) { + return 0; + } else { + return Math.max.apply(null, values); + } +} -- 2.34.1 From a0f907d08fb8e1eadd978df36a7439445b94ca88 Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 08:40:42 -0300 Subject: [PATCH 04/11] feat: solucao fibonacci --- 04-fibonacci/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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]; +} -- 2.34.1 From 8d311cb1e5a383e79859d38ba7c3bc76e23d438c Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 10:04:23 -0300 Subject: [PATCH 05/11] feat: solucao isPrime --- 05-isPrime/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; +} -- 2.34.1 From d4646cd89ef2494412e9e77ce26be3ade8a4b845 Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 10:09:51 -0300 Subject: [PATCH 06/11] feat: solucao sum --- 06-sum/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; +} -- 2.34.1 From bb9ac73956360acd5cd04eb10a06f2ad8a0eb38e Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 10:49:04 -0300 Subject: [PATCH 07/11] feat: solucao sumEven --- 07-sumEven/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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; + } +} -- 2.34.1 From 2c23f938b60251a00120a5d3ee1adda874d55545 Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 10:55:14 -0300 Subject: [PATCH 08/11] feat: solucao isAnagram --- 08-isAnagram/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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; + } +} -- 2.34.1 From c7a757284144d1ca30796ea30a368c4f49a9d28c Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 10:59:45 -0300 Subject: [PATCH 09/11] feat: solucao mostRepeatedChar --- 09-mostRepeatedChar/index.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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}`; +} -- 2.34.1 From 1231f40660222099cba3ec7e8b80c64b089167a5 Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 15:01:37 -0300 Subject: [PATCH 10/11] refactor: altera solucao maxValue --- 03-maxValue/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/03-maxValue/index.js b/03-maxValue/index.js index a78ce0f..93d537a 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,8 +1,12 @@ export function maxValue(values) { // implementar logica aqui + let max = values.reduce(function (a, b) { + return Math.max(a, b); + }, -Infinity); + if (values.length === 0) { return 0; } else { - return Math.max.apply(null, values); + return max; } } -- 2.34.1 From dfe39deb46b9e9a0bd3dac1a98c9ab54115e6032 Mon Sep 17 00:00:00 2001 From: Rafael Sampaio Date: Fri, 28 Oct 2022 16:54:30 -0300 Subject: [PATCH 11/11] feat: solucao longestWords --- 10-longestWords/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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); +} -- 2.34.1