From 93894fcc616510b69d3482a637801d049d63ebd8 Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 14:13:45 -0300 Subject: [PATCH 01/10] feat(greeting): Adicionando algoritmo que retorna uma saudacao. --- 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}`; } From 71b657274463eb03ffd881c62076f1e8c0eef2bf Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 14:21:30 -0300 Subject: [PATCH 02/10] feat(triangleArea): Adicionando o algoritmo que retorna a area de um triangulo. --- 02-triangleArea/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/02-triangleArea/index.js b/02-triangleArea/index.js index 7628fcd..90524e0 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 +export function triangleArea(base, height) { + let area = (base * height) / 2; + return area; +} From e74fc971cf9305dc05346149fbc75e9fc3736e1a Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 14:36:39 -0300 Subject: [PATCH 03/10] feat(maxValue): Adicionando algoritmo que retorna o valor maximo de um vetor. --- 03-maxValue/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..bd5b22d 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,13 @@ export function maxValue(values) { - // implementar logica aqui - -} \ No newline at end of file + let max = values[0]; + if (values.length === 0) { + return 0; + } else { + for (let index = 0; index <= values.length; index++) { + if (max < values[index]) { + max = values[index]; + } + } + return max; + } +} From c6ca6f99f0b3fdc9aea33d1cc4f43806faa66ad6 Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 14:44:32 -0300 Subject: [PATCH 04/10] feat(fibonacci): Adicionando algoritmo que retorna o resultado da sequencia de fibonacci. --- 04-fibonacci/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..e5ccd64 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,15 @@ export function fibonacci(value) { - // implementar logica aqui - -} \ No newline at end of file + let vet = []; + vet.push(0); + vet.push(1); + if (value == 0) { + return vet[0]; + } else if (value == 1) { + return vet[1]; + } else { + for (let index = 2; index <= value; index++) { + vet[index] = vet[index - 2] + vet[index - 1]; + } + } + return vet.at(-1); +} From f442d2d8182f6aa341e33fe96e526243c8c72a1c Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 14:50:30 -0300 Subject: [PATCH 05/10] feat(isPrime): Adicionando algoritmo que retorna se um numero e primo ou nao. --- 04-fibonacci/index.test.js | 60 +++++++++++++++++++------------------- 05-isPrime/index.js | 15 ++++++++-- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/04-fibonacci/index.test.js b/04-fibonacci/index.test.js index b518d0a..7946517 100644 --- a/04-fibonacci/index.test.js +++ b/04-fibonacci/index.test.js @@ -1,39 +1,39 @@ -import { fibonacci } from "." +import { fibonacci } from "."; -describe('fibonacci', () => { - it('Dever retornar 0 quando passamos o valor 0', () => { - expect(fibonacci(0)).toBe(0) - }) +describe("fibonacci", () => { + it("Dever retornar 0 quando passamos o valor 0", () => { + expect(fibonacci(0)).toBe(0); + }); - it('Dever retornar 1 quando passamos o valor 1', () => { - expect(fibonacci(1)).toBe(1) - }) + it("Dever retornar 1 quando passamos o valor 1", () => { + expect(fibonacci(1)).toBe(1); + }); - it('Dever retornar 1 quando passamos o valor 2', () => { - expect(fibonacci(2)).toBe(1) - }) + it("Dever retornar 1 quando passamos o valor 2", () => { + expect(fibonacci(2)).toBe(1); + }); - it('Dever retornar 2 quando passamos o valor 3', () => { - expect(fibonacci(3)).toBe(2) - }) + it("Dever retornar 2 quando passamos o valor 3", () => { + expect(fibonacci(3)).toBe(2); + }); - it('Dever retornar 3 quando passamos o valor 4', () => { - expect(fibonacci(4)).toBe(3) - }) + it("Dever retornar 3 quando passamos o valor 4", () => { + expect(fibonacci(4)).toBe(3); + }); - it('Dever retornar 5 quando passamos o valor 5', () => { - expect(fibonacci(5)).toBe(5) - }) + it("Dever retornar 5 quando passamos o valor 5", () => { + expect(fibonacci(5)).toBe(5); + }); - it('deve retonar 8 quando passamos o valor 6', () => { - expect(fibonacci(6)).toBe(8) - }) + it("deve retonar 8 quando passamos o valor 6", () => { + expect(fibonacci(6)).toBe(8); + }); - it('Dever retornar 9227465 quando passamos o valor 35', () => { - expect(fibonacci(35)).toBe(9227465) - }) + it("Dever retornar 9227465 quando passamos o valor 35", () => { + expect(fibonacci(35)).toBe(9227465); + }); - it('Dever retornar 1836311903 quando passamos o valor 46', () => { - expect(fibonacci(46)).toBe(1836311903) - }) -}) \ No newline at end of file + it("Dever retornar 1836311903 quando passamos o valor 46", () => { + expect(fibonacci(46)).toBe(1836311903); + }); +}); diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..5ffe9dc 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,13 @@ export function isPrime(value) { - // implementar logica aqui - -} \ No newline at end of file + let contador = 0; + for (let index = 0; index <= value; index++) { + if (value % index === 0) { + contador = contador + 1; + } + } + if (contador === 2) { + return true; + } else { + return false; + } +} From 1aad4cb5edb84e4cdee3401d5298b78864e9584b Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 14:56:44 -0300 Subject: [PATCH 06/10] feat(sum): Adicionando algoritmo que retorna a soma de todos os numeros de um vetor. --- 06-sum/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..992c821 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,7 @@ export function sum(values) { - // implementar logica aqui - -} \ No newline at end of file + let soma = 0; + for (let index = 0; index < values.length; index++) { + soma = soma + values[index]; + } + return soma; +} From a817a9a1b1e2cc1d2baa7c04e0d69291acbb9ada Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 15:02:05 -0300 Subject: [PATCH 07/10] feat(sumEven): Adicionando algoritmo que retorna a soma de todos os numeros pares de um vetor. --- 06-sum/readme.md | 8 ++++---- 07-sumEven/index.js | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/06-sum/readme.md b/06-sum/readme.md index 1a05476..82a18b0 100644 --- a/06-sum/readme.md +++ b/06-sum/readme.md @@ -5,7 +5,7 @@ Faça um algoritmo que retorne a soma de todos os números de um array ## Exemplo ```js -sum([1, 2, 3, 4, 5]) // 15 -sum([10, 10, 10, 10]) // 40 -sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) // 55 -``` \ No newline at end of file +sum([1, 2, 3, 4, 5]); // 15 +sum([10, 10, 10, 10]); // 40 +sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // 55 +``` diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..fcfc6e3 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,9 @@ export function sumEven(value) { - // implementar logica aqui - -} \ No newline at end of file + let somaPares = 0; + for (let index = 0; index < value.length; index++) { + if (value[index] % 2 === 0) { + somaPares = somaPares + value[index]; + } + } + return somaPares; +} From d5dc003ecc1459a4487282f5e71d6e331924a602 Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 15:10:16 -0300 Subject: [PATCH 08/10] feat(isAnagram): Adicionando algoritmo que retorna se uma palavra e anagrama da outra. --- 08-isAnagram/index.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..c73b1e6 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,22 @@ export function isAnagram(word1, word2) { - // implementar logica aqui - -} \ No newline at end of file + let word1Lower = Array.from(word1.toLowerCase()); + let word2Lower = Array.from(word2.toLowerCase()); + if (word1Lower.length !== word2Lower.length) { + return false; + } + let contador = 0; + while (word1.length !== contador) { + let letraword2 = word2Lower[0]; + if (word1Lower.indexOf(letraword2) !== -1) { + let indice = word1Lower.indexOf(letraword2); + word1Lower.splice(indice, 1); + word2Lower.shift(); + } + contador = contador + 1; + } + if (word1Lower.length === 0 && word2Lower.length === 0) { + return true; + } else { + return false; + } +} From 52deadb72d3a728227edb22ac4712438f9ff923d Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 15:22:02 -0300 Subject: [PATCH 09/10] feat(mostRepeatedChar): Adicionando algoritmo que retorna a letra mais repetida de uma string. --- 08-isAnagram/readme.md | 12 +++++------- 09-mostRepeatedChar/index.js | 30 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/08-isAnagram/readme.md b/08-isAnagram/readme.md index 602e336..b95b114 100644 --- a/08-isAnagram/readme.md +++ b/08-isAnagram/readme.md @@ -1,13 +1,11 @@ -# Desafio 08: Anagrama +# Desafio 08: Anagrama Faça um algoritmo que retorne se um palavra é anagram da outra ## Exemplo ```js - -isAnagram('roma', 'amor') // true -isAnagram('roma', 'amora') // false -isAnagram('roma', 'amora') // false - -``` \ No newline at end of file +isAnagram("roma", "amor"); // true +isAnagram("roma", "amora"); // false +isAnagram("roma", "amora"); // false +``` diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..8d6710b 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,28 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" -} \ No newline at end of file + let vetChar = []; + let qtdCharAtual = 0; + let charAtual = ""; + let qtdCharMaior = 0; + let charMaior = ""; + for (let index = 0; index < text.length; index++) { + const element = text[index]; + if (!vetChar.includes(element)) { + vetChar.push(element); + } + } + for (let chave = 0; chave <= vetChar.length; chave++) { + charAtual = vetChar[chave]; + qtdCharAtual = 0; + for (let index = 0; index <= text.length; index++) { + if (vetChar[chave] === text[index]) { + qtdCharAtual = qtdCharAtual + 1; + } + if (qtdCharMaior < qtdCharAtual && vetChar[chave] !== text[index]) { + charMaior = charAtual; + qtdCharMaior = qtdCharAtual; + } + } + } + + return charMaior; +} From 57a410151f93c4939ae651bfe9156df018aecbb4 Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 15:32:45 -0300 Subject: [PATCH 10/10] feat(longestWords): Adicionando algoritmo que retorna uma lista com as palavras mais longas de uma lista de palavras. --- 10-longestWords/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..9b07942 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,15 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + let vetWords = []; + + for (let index = 0; index < words.length; index++) { + if (vetWords.length === 0) { + vetWords.push(words[index]); + } else if (vetWords[0].length < words[index].length) { + vetWords = []; + vetWords.push(words[index]); + } else if (vetWords[0].length === words[index].length) { + vetWords.push(words[index]); + } + } + return vetWords; +}