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..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; +} 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; + } +} 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); +} 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; + } +} 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; +} 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; +} 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; + } +} 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; +} 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; +}