diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/01-greeting/index.js b/01-greeting/index.js index 8f551af..f99d6be 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..3cf4ee7 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,3 @@ export function triangleArea(base, height) { - // your code here + return(base*height)/2 } \ No newline at end of file diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..faa5d6e 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,11 @@ export function maxValue(values) { - // implementar logica aqui - + if (values == `${[]}`) { + return 0 + + } else { + + return Math.max.apply(null, values); + + } + } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..e6cddd0 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,17 @@ export function fibonacci(value) { - // implementar logica aqui - + if (value < 1) return 0 + if (value <= 2) return 1 + let fibonnaci1 = 0 + let fibonnaci2 = 1 + let fibx = value + + for (let i = 2; i <= value; i++) { + + fibx = fibonnaci2 + fibonnaci1 + fibonnaci1 = fibonnaci2 + fibonnaci2 = fibx + } + + return fibx + } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..2f59911 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,10 @@ export function isPrime(value) { - // implementar logica aqui - + for (let i = 2; i < value; i++) { + if (value % i == 0) { + return false + } + + } + return value > 1 + } \ No newline at end of file diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..b32c77a 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,11 @@ export function sum(values) { - // implementar logica aqui - + if (values.length) { + + return values.reduce(function (soma, i) { + + return soma + i + }) + } + return 0 + } \ No newline at end of file diff --git a/06-sum/index.test.js b/06-sum/index.test.js index a1c8d55..8dcce2a 100644 --- a/06-sum/index.test.js +++ b/06-sum/index.test.js @@ -44,6 +44,6 @@ describe("sum", () => { }); it("Dever retornar -40 quando passamos o array [-2, -7, -31]", () => { - expect(sum([-2, -7, -31])).toBe(-51); + expect(sum([-2, -7, -31])).toBe(-40); }) }); \ No newline at end of file diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..9ae806f 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,10 @@ export function sumEven(value) { - // implementar logica aqui - + let resultado = 0 + for (const number of value) { + if (number % 2 == 0) { + resultado += number + } + } + return resultado + } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..b4afb74 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,28 @@ export function isAnagram(word1, word2) { - // implementar logica aqui - -} \ No newline at end of file + + if (word1.length !== word2.length) { + return false; + } else { + if ( + word1.toLowerCase().split("").sort().join("") === + word2.toLowerCase().split("").sort().join("") + ) { + return true; + } else { + return false; + } + } +} + + + + + + + + + + + + + diff --git a/08-isAnagram/index.test.js b/08-isAnagram/index.test.js index 4d7c8a7..b2998f9 100644 --- a/08-isAnagram/index.test.js +++ b/08-isAnagram/index.test.js @@ -5,23 +5,23 @@ describe("isAnagram", () => { expect(isAnagram("roma", "amor")).toBe(true); }); - ít("Dever retornar true quando passamos as palavras \"Buckethead\" e \"DeathCubeK\"", () => { + it("Dever retornar true quando passamos as palavras \"Buckethead\" e \"DeathCubeK\"", () => { expect(isAnagram("Buckethead", "DeathCubeK")).toBe(true); }); - ít("Dever retornar true quando passamos as palavras \"Twoo\" e \"WooT\"", () => { + it("Dever retornar true quando passamos as palavras \"Twoo\" e \"WooT\"", () => { expect(isAnagram("Twoo", "WooT")).toBe(true); }); - ít("Dever retornar false quando passamos as palavras \"dumble\" e \"bumble\"", () => { + it("Dever retornar false quando passamos as palavras \"dumble\" e \"bumble\"", () => { expect(isAnagram("dumble", "bumble")).toBe(false); }); - ít("Dever retornar false quando passamos as palavras \"ound\" e \"round\"", () => { + it("Dever retornar false quando passamos as palavras \"ound\" e \"round\"", () => { expect(isAnagram("ound", "round")).toBe(false); }); - ít("Dever retornar false quando passamos as palavras \"apple\" e \"pale\"", () => { + it("Dever retornar false quando passamos as palavras \"apple\" e \"pale\"", () => { expect(isAnagram("apple", "pale")).toBe(false); }); }); \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..8b914b9 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 + + + const palavra = {}; + let maximo = 0; + let repetido = ''; + + for(let letra of text){ + if(palavra[letra]){ + palavra[letra]++; + }else{ + palavra[letra] = 1; + } + } + + for(let letra in palavra){ + if(palavra[letra] > maximo){ + maximo = palavra[letra]; + repetido = letra; + } + } + + return repetido +} + + + + \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..377fa39 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,24 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + + let letra = words + let tamanho = 0 + let maximo = [' '] + + for (let i = 0; i < letra.length; i++) { + if (letra[i].length >= tamanho) { + tamanho = letra[i].length + if (maximo[maximo.length - 1].length < letra[i].length) { + maximo = [] + maximo.push(letra[i]) + } + else { + maximo = [...maximo, letra[i]] + } + } + } + return [...maximo] +} + + + +