Merge pull request 'feature/algoritmos' (#1) from feature/algoritmos into master

Reviewed-on: #1
This commit is contained in:
Gabriel Gomes Fernandes 2022-11-01 02:02:42 +00:00
commit 894f1eb5d2
10 changed files with 36 additions and 6 deletions

View File

@ -1,4 +1,5 @@
export function greet(name) {
// implementar logica aqui
return "";
return `Hello ${name}` ;
}

View File

@ -1,3 +1,4 @@
export function triangleArea(base, height) {
// your code here
return base * height / 2 ;
}

View File

@ -1,4 +1,9 @@
export function maxValue(values) {
// implementar logica aqui
if (values.length == 0)
return 0;
return Math.max(...values,);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -1,4 +1,4 @@
export function sum(values) {
// implementar logica aqui
return values.reduce((total, values) => total + values, 0);
}

View File

@ -1,4 +1,4 @@
export function sumEven(value) {
// implementar logica aqui
return value.reduce((acc,curr)=>acc + (curr % 2 == 0 ? curr : 0), 0);
}

View File

@ -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;
}

View File

@ -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, '');
}

View File

@ -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;
}, []);
}