diff --git a/01-greeting/index.js b/01-greeting/index.js index 8f551af..6df56c8 100644 --- a/01-greeting/index.js +++ b/01-greeting/index.js @@ -1,4 +1,10 @@ export function greet(name) { // implementar logica aqui - return ""; -} + let hello; + if (name) + hello = 'Hello ' + name; + else + hello = 'Adicione um nome na funcão'; + + return hello; +} \ No newline at end of file diff --git a/02-triangleArea/index.js b/02-triangleArea/index.js index 7628fcd..e8ea750 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,9 @@ export function triangleArea(base, height) { // your code here + if ((base > 0) && (height > 0)) { + let area = (base * height) / 2; + return area; + } + else + return console.log('Base e altura devem ser maior a 0') } \ No newline at end of file diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..8571f7c 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,13 @@ export function maxValue(values) { // implementar logica aqui - + let numeromaior = 0; + if (values[0] < numeromaior) + numeromaior = values[0]; + let i = 0; + for (i = 0; i < values.length; i++){ + if (numeromaior < values[i]){ + numeromaior = values[i]; + } + } + return numeromaior; } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..413eee1 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,13 @@ export function fibonacci(value) { // implementar logica aqui + let fibo = []; + let i = 0; + for (i = 0 ; i <= value; i++) { + if (i < 2) + fibo[i] = i; + else + fibo[i] = fibo[i-1] + fibo[i-2]; + } + return fibo[value]; } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..bf896f6 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,14 @@ export function isPrime(value) { // implementar logica aqui + let div = 0; + let i; + for (i = 1; i <= value; i++) { + if ((value % i) == 0) + div++; + } + if (div === 2) + return true; + else + return false } \ No newline at end of file diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..9211b82 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,12 @@ export function sum(values) { // implementar logica aqui + let suma = 0; + let i = 0; + if (values) { + for (i = 0; i < values.length; i++){ + suma+= values[i]; + } + } + return suma; } \ No newline at end of file diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..03e94ca 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,12 @@ export function sumEven(value) { // implementar logica aqui - + let suma = 0; + let i; + if (value) { + for (i = 0; i < value.length; i++){ + if (value[i] % 2 == 0) + suma+= value[i]; + } + } + return suma; } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..d47e20b 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,22 @@ export function isAnagram(word1, word2) { // implementar logica aqui + if (word1 != word2){ + if (word1.lenght == word2.lenght){ + word1 = word1.toLowerCase(); + word2 = word2.toLowerCase(); + let teste = word1.split(''); + let origin = word2.split(''); + teste = teste.sort(); + origin = origin.sort(); + teste = teste.join(); + origin = origin.join(); + if (teste == origin) + return true; + else + return false; + } + else return false; +} +else return false; } \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..9fe9539 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,25 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + if (text.length == 0) + return console.log('Escreva alguma coisa pra consultar'); + else { + let cont = 1; + let letra; + + for (let i = 0; i < text.length; i++) { + let cont2 = 1; + for (let j = 0; j < text.length; j++) { + if (j !== i) { + if (text[i] === text[j]) + cont2++; + if (cont2 > cont) { + cont = cont2; + letra = text[i]; + } + } + } + } + return letra; + } + } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..cfe1c28 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,19 @@ export function longestWords(words) { // implementar logica aqui + if (words.length == 0) + return console.log('Escreva as palavras a serem consultar'); + else { + let cont = words[0].length; + for (let i = 1; i < words.length; i++) { + if (cont < words[i].length) + cont = words[i].length; + } + let longest = []; + for (let j = 0; j < words.length; j++) { + if (cont == words[j].length) + longest.push(words[j]); + } + return longest; + } } \ No newline at end of file