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..8f90bb9 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 diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..ec4d9e6 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,9 @@ export function maxValue(values) { // implementar logica aqui - + let maxValor = Math.max(...values); + if (values == `${[]}`) { + return 0 ; + } else { + return maxValor; + } } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..5c82af6 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,8 @@ export function fibonacci(value) { // implementar logica aqui - + let arr = [ 0, 1 ]; + for (let i = 2; i < value + 1; i++) { + arr.push ( arr [ i - 2 ] + arr [ i - 1 ] ) + } + return arr [ value ]; } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..0880725 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,16 @@ export function isPrime(value) { // implementar logica aqui - + { if ( value === 1 ) { + return false; + } else if ( value === 2 ) { + return true; + } else { + for ( var x = 2; x < value; x++ ) { + if ( value % x === 0 ) { + return false; + } + } + return true; + } + } } \ No newline at end of file diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..315dafd 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 index = 0; index < values.length; index += 1 ) { + soma = soma + values [ index ] ; + } + return soma; } \ No newline at end of file diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..c028c98 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,10 @@ export function sumEven(value) { // implementar logica aqui - + let soma = 0; + for( let index = 0; index < value.length; index += 1 ) { + if (value[index] % 2 == 0) { + soma = soma + value [ index ] ; + } + } + return soma; } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..a27523c 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 + if (cleanString(word1) === cleanString(word2)) { + return true; + } else { + return false; + }; +} + function cleanString(str) { + return str.toLowerCase().split('').sort().join(); + } \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..8baa82c 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,9 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let hashmap = {}, resposta; + text.split('').reduce((acumulador, letra) => { + hashmap [ letra ] = hashmap [ letra ] + 1 || 1 + resposta = hashmap [ letra ] >= acumulador ? letra : resposta + return acumulador = hashmap [ letra ] > acumulador ? acumulador + 1 : acumulador }, 1 ) + return resposta; } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..4eff8ab 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,11 @@ +import { arrayBuffer } from "stream/consumers"; + export function longestWords(words) { // implementar logica aqui - -} \ No newline at end of file + let maioresPalavras = ""; + for ( const word of words ) { + if ( word.length > maioresPalavras.length ) { + maioresPalavras = word; } + } + return words.filter ( ( word ) => word.length == maioresPalavras.length ) ; + }