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..5346213 100644 --- a/02-triangleArea/index.js +++ b/02-triangleArea/index.js @@ -1,3 +1,5 @@ export function triangleArea(base, height) { // your code here + let area = (base * height)/2; + return area; } \ No newline at end of file diff --git a/03-maxValue/index.js b/03-maxValue/index.js index e433b31..15e7cd1 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,12 @@ export function maxValue(values) { // implementar logica aqui - + if (values.length) { + let max = -Infinity; + + for (let num of values) { + max = num > max ? num : max; + } + return max; + } + return 0; } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..bbdc320 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,5 @@ export function fibonacci(value) { // implementar logica aqui - + var sqrt5 = Math.sqrt(5); + return Math.round(Math.pow(((1 + sqrt5) / 2), value) / sqrt5); } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..db0459d 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,8 @@ 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..b927d12 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,8 @@ export function sum(values) { // implementar logica aqui - + let sumOfArrays = 0; + for(let index = 0; index < values.length; index +=1) { + sumOfArrays = sumOfArrays + values[index]; + } + return sumOfArrays; } \ No newline at end of file diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..804eb90 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,10 @@ export function sumEven(value) { // implementar logica aqui - + let sumOfEven = 0; + for (let i = 0; i < value.length; i++) { + if (value[i] % 2 === 0) { + sumOfEven = sumOfEven + value[i]; + } + } + return sumOfEven; } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..7600588 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,11 @@ export function isAnagram(word1, word2) { // implementar logica aqui - + const Anagram = str => + str + .toLowerCase() + .replace(/[^a-z0-9]/gi, '') + .split('') + .sort() + .join(''); + return Anagram(word1) === Anagram(word2); } \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..5c17bdb 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,12 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let max = 0, + maxChar = ''; + text.split('').forEach(function(char){ + if(text.split(char).length > max) { + max = text.split(char).length; + maxChar = char; + } + }); + return maxChar; } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..784e7b0 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,5 @@ export function longestWords(words) { // implementar logica aqui - + let maxWord = Math.max(...words.map( elem => elem.length)) + return words.filter(elem => elem.length === maxWord) } \ No newline at end of file