diff --git a/01-greeting/index.js b/01-greeting/index.js index 8f551af..85600ec 100644 --- a/01-greeting/index.js +++ b/01-greeting/index.js @@ -1,4 +1,5 @@ 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..71ecb21 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..a588023 100644 --- a/03-maxValue/index.js +++ b/03-maxValue/index.js @@ -1,4 +1,9 @@ export function maxValue(values) { // implementar logica aqui + if (values.length == 0) + + return 0; + + return Math.max(...values,); } \ No newline at end of file diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..be20017 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,7 @@ export function fibonacci(value) { // implementar logica aqui - + let phi = (1 + Math.sqrt(5))/2; + let asymp = Math.pow(phi, value) / Math.sqrt(5); + + return Math.round(asymp); } \ No newline at end of file diff --git a/05-isPrime/index.js b/05-isPrime/index.js index ec9c4ac..e61acdc 100644 --- a/05-isPrime/index.js +++ b/05-isPrime/index.js @@ -1,4 +1,9 @@ export function isPrime(value) { // implementar logica aqui + if (value === 0 || value === 1) return false; + for (let i = 2; i <= Math.sqrt(value); i++) { + if (value % i === 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..4d6b912 100644 --- a/06-sum/index.js +++ b/06-sum/index.js @@ -1,4 +1,4 @@ export function sum(values) { // implementar logica aqui - + return values.reduce((total, values) => total + values, 0); } \ No newline at end of file diff --git a/07-sumEven/index.js b/07-sumEven/index.js index bb1e095..3b23156 100644 --- a/07-sumEven/index.js +++ b/07-sumEven/index.js @@ -1,4 +1,4 @@ export function sumEven(value) { // implementar logica aqui - + return value.reduce((acc,curr)=>acc + (curr % 2 == 0 ? curr : 0), 0); } \ No newline at end of file diff --git a/08-isAnagram/index.js b/08-isAnagram/index.js index 918308a..1c82f70 100644 --- a/08-isAnagram/index.js +++ b/08-isAnagram/index.js @@ -1,4 +1,6 @@ export function isAnagram(word1, word2) { // implementar logica aqui - + var y = word1.toLowerCase().split("").sort().join(""), + z = word2.toLowerCase().split("").sort().join(""); + return (z === y) ? true : false; } \ No newline at end of file diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..f10b302 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,8 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const charHolder = text.toLowerCase().split('').reduce((ac,a) => (ac[a] = ac[a] + 1 || 1, ac), {}); + + let max = Math.max(...Object.values(charHolder)); + + return Object.entries(charHolder).reduce((ac,[k,v]) =>v === max ? ac + k : ac, ''); } \ No newline at end of file diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..ab58490 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,13 @@ export function longestWords(words) { // implementar logica aqui + return words.reduce((r, s, i) => { + if (!i || r[0].length < s.length) { + return [s]; + } + if (r[0].length === s.length) { + r.push(s); + } + return r; + }, []); } \ No newline at end of file