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..d54f939 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,3 @@ -export function triangleArea(base, height) { - // your code here -} \ No newline at end of file +export function triangleArea(base, height) { + return (base * height) / 2; +} diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..c47fa02 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,11 @@ export function maxValue(values) { // implementar logica aqui - -} \ No newline at end of file + if (values != `${[]}`) { + let max = values.reduce(function (a, b) { + return Math.max(a, b); + }, -Infinity); + return max; + } else { + return 0; + } +} diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..d3ec854 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,18 @@ export function fibonacci(value) { // implementar logica aqui - -} \ No newline at end of file + let penultimo = 0, + ultimo = 1; + let numero; + let arr = []; + if (value < 2) { + return value; + } else { + for (let count = 2; count <= value; count++) { + numero = ultimo + penultimo; + penultimo = ultimo; + ultimo = numero; + arr.push(ultimo); + } + return arr[value - 2]; + } +} diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..2b2b45d 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,14 @@ export function isPrime(value) { // implementar logica aqui - -} \ No newline at end of file + let divisores = 0; + for (let index = 1; index <= value; index++) { + if (value % index == 0) { + divisores++; + } + } + if (divisores == 2) { + return true; + } else { + return false; + } +} diff --git a/06-sum/index.js b/06-sum/index.js index ebc2ee1..d071540 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,8 @@ export function sum(values) { // implementar logica aqui - -} \ No newline at end of file + function add(a, b) { + return a + b; + } + var soma = values.reduce(add, 0); + return soma; +} diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..2aa5e6a 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,15 @@ export function sumEven(value) { // implementar logica aqui - -} \ No newline at end of file + const arr = []; + for (let index = 0; index < value.length; index++) { + const element = value[index]; + if (element % 2 == 0) { + arr.push(element); + } + } + function add(a, b) { + return a + b; + } + var soma = arr.reduce(add, 0); + return soma; +} diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..46c6e30 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,14 @@ export function isAnagram(word1, word2) { // implementar logica aqui - -} \ No newline at end of file + if (word1.length === word2.length) { + let word1Lower = word1.toLowerCase().split("").sort(); + let word2Lower = word2.toLowerCase().split("").sort(); + if (word1Lower.join() == word2Lower.join()) { + return true; + } else { + return false; + } + } else { + return false; + } +} diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..fbde00f 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,10 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" -} \ No newline at end of file + // implementar logica aqui + let textLower = text.toLowerCase().split("").sort(); + for (let index = 1; index < textLower.length; index++) { + textLower = textLower.filter((e, i, a) => a.indexOf(e) !== i); + } + + let letter = [...new Set(textLower)]; + return letter.join(""); +} diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..7981158 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,17 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + // implementar logica aqui + let max_string_size = 0; + let big_string_list = []; + + for (let string of words) { + const string_size = string.length; + + if (string_size > max_string_size) { + big_string_list = [string]; + max_string_size = string_size; + } else if (string_size == max_string_size) { + big_string_list.push(string); + } + } + return big_string_list; +}