From d0a7ee905d40ed2ece83920f47e564f5a30b8443 Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sat, 29 Oct 2022 00:45:20 -0300 Subject: [PATCH 01/11] Feat(Desafio_2.1): Cria resposta desafio 2.1 --- 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 995c55c829484fe11ad041289b4e93231275dc38 Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sat, 29 Oct 2022 00:50:31 -0300 Subject: [PATCH 02/11] Feat(Desafio_2.2): Cria resposta desafio 2.2 --- 02-triangleArea/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/02-triangleArea/index.js b/02-triangleArea/index.js index 7628fcd..d26b62a 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 -- 2.34.1 From b27cae87952e7c6b911eb40bd86f903f77e9514e Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sat, 29 Oct 2022 03:34:48 -0300 Subject: [PATCH 03/11] Feat(Desafio_2.3): Cria resposta desafio 2.3 --- 03-maxValue/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..3b43b38 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 > 0){ + return Math.max.apply(null, values); + } + else{ + return 0; + } } \ No newline at end of file -- 2.34.1 From cf7023cb7e2fb757df2976b4570f7d6d57d120b2 Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sat, 29 Oct 2022 04:07:37 -0300 Subject: [PATCH 04/11] Feat(Desafio_2.4): Cria resposta desafio 2.4 --- 04-fibonacci/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..34e2e43 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,7 @@ export function fibonacci(value) { // implementar logica aqui - -} \ No newline at end of file + if(value <= 1){ + return value + } + return fibonacci(value - 1) + fibonacci(value - 2) +} -- 2.34.1 From 33f0b9cf1c1852f9cf8586cfa8b91c1317e0a0d9 Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sat, 29 Oct 2022 04:13:54 -0300 Subject: [PATCH 05/11] Feat(Desafio_2.5): Cria resposta desafio 2.5 --- 05-isPrime/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..9959aee 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,9 @@ export function isPrime(value) { // implementar logica aqui - + for (let n = 2; n < value; n++) + if (value % n === 0){ + return false + } + return value > 1 + } \ No newline at end of file -- 2.34.1 From e35e6c76f3822d5cd4c4070cbecb59815194f20f Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sat, 29 Oct 2022 04:20:25 -0300 Subject: [PATCH 06/11] Feat(Desafio_2.6): Cria resposta desafio 2.6 --- 06-sum/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..5649405 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 -- 2.34.1 From 0bc53f12d5f28c10335a5f05125b4f3cec0b3de2 Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sat, 29 Oct 2022 04:24:24 -0300 Subject: [PATCH 07/11] Feat(Desafio_2.7): Cria resposta desafio 2.7 --- 07-sumEven/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..ec9bcfb 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,9 @@ 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 -- 2.34.1 From a759594012df03386c46ec7296bf470c7c7151cb Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sat, 29 Oct 2022 04:34:11 -0300 Subject: [PATCH 08/11] Feat(Desafio_2.8): Cria resposta desafio 2.8 --- 08-isAnagram/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..6a44003 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,12 @@ export function isAnagram(word1, word2) { // implementar logica aqui - + if(word1.length !== word2.length){ + return false; + } + let palavra_1 = word1.toLowerCase().split('').sort().join(''); + let palavra_2 = word2.toLowerCase().split('').sort().join(''); + + let anagram = (palavra_1 === palavra_2) + return anagram + } \ No newline at end of file -- 2.34.1 From 2d3fe20e79093fe26d994009f2b022bc38f44409 Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sat, 29 Oct 2022 04:43:39 -0300 Subject: [PATCH 09/11] Feat(Desafio_2.9): Cria desafio 2.9 --- 09-mostRepeatedChar/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..c9e5eb3 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,18 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const tl = text.length; + const freq = {}; + let maxFreq = 0; + let maxChar; + for (let i = 0; i < tl; ++i){ + const isPair = (text.charCodeAt(i) & 0xF800) == 0xD800; + const c = isPair ? text.substr(i++, 2) : text[i]; + const f = (freq[c] || 0) + 1; + freq[c] = f; + if (f > maxFreq){ + maxFreq = f; + maxChar = c; + } + } + return maxChar } \ No newline at end of file -- 2.34.1 From 5e63b3c3a2ff7d8c6c61e1c568780fa153af86ad Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Sun, 30 Oct 2022 03:11:50 -0300 Subject: [PATCH 10/11] Feat(Desafio_2.10): Cria resposta desafio 2.10 --- 10-longestWords/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..aac5153 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,10 @@ export function longestWords(words) { // implementar logica aqui + let longest = "" + for (let word of words){ + if (word.length > longest.length) longest = word; + } + let longest_words = words.filter(item => item.length >= longest.length) + return longest_words } \ No newline at end of file -- 2.34.1 From 42c6514828a873251e5067831f43a4c22e58ac7e Mon Sep 17 00:00:00 2001 From: Rhayllon Date: Mon, 31 Oct 2022 21:27:51 -0300 Subject: [PATCH 11/11] Refactor(Desafio2.4): Muda o codigo para calcular fibonacci de maneira mais peformatica --- 04-fibonacci/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 34e2e43..f316e95 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -3,5 +3,11 @@ export function fibonacci(value) { if(value <= 1){ return value } - return fibonacci(value - 1) + fibonacci(value - 2) + let v1 = 0, v2 = 1, v3 = 1; + for (let i = 2; i <= value ; i++) { + v3 = v1 + v2; + v1 = v2; + v2 = v3 + } + return v3; } -- 2.34.1