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

Reviewed-on: #1
This commit is contained in:
Vitor Soares 2022-10-28 23:12:43 +00:00
commit 551fc7f7eb
10 changed files with 65 additions and 7 deletions

View File

@ -1,4 +1,4 @@
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 values.reduce((ac, value) => {
if(ac > value) return ac;
return value
}, );
}

View File

@ -1,4 +1,15 @@
export function fibonacci(value) {
// implementar logica aqui
let n1 = 0
let n2 = 1
let fibo
for (let i = 1; i <= value; i++) {
fibo = n1 + n2;
n1 = n2;
n2 = fibo;
};
return n1
}

View File

@ -1,4 +1,9 @@
export function isPrime(value) {
// implementar logica aqui
for (let i = 2; i < value; i++) {
if(value % i == 0) return false;
};
return value > 1
}

View File

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

View File

@ -1,4 +1,8 @@
export function sumEven(value) {
// implementar logica aqui
return value.filter((number) => {
if(number % 2 == 0) return number;
}).reduce((ac, number) => {
return ac += number;
}, 0);
}

View File

@ -1,4 +1,8 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
word1 = word1.toLowerCase().split('').sort().join('');
word2 = word2.toLowerCase().split('').sort().join('');
if(word1 == word2) return true;
return false;
}

View File

@ -1,4 +1,14 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
let max = 0
let maxChar = ''
text.split('').forEach((char) => {
if(text.split(char).length > max) {
max = text.split(char).length;
maxChar = char;
}
});
return maxChar
}

View File

@ -1,4 +1,20 @@
export function longestWords(words) {
// implementar logica aqui
let long = ''
const longest = words.map((word) => {
if(word.length > long.length) {
long = word;
}
return word
}).filter((word) => {
if(word.length === long.length) {
return word;
}
});
return longest
}