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

Reviewed-on: #1
This commit is contained in:
Bernardo Cunha Ernani Waldhelm 2022-11-01 19:27:09 +00:00
commit 3cf0e1ceeb
10 changed files with 84 additions and 9 deletions

View File

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

View File

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

View File

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

View File

@ -1,4 +1,13 @@
export function fibonacci(value) {
// implementar logica aqui
if (value <= 1) {
return value;
}
let arr = [0, 1];
for (let i = 2; i < value + 1; i++) {
arr[i] = arr[i - 2] + arr[i - 1];
}
return arr[value];
}

View File

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

View File

@ -1,4 +1,8 @@
export function sum(values) {
// implementar logica aqui
let soma = 0;
for (let i = 0; i < values.length; i++) {
soma += values[i];
}
return soma;
}

View File

@ -1,4 +1,11 @@
export function sumEven(value) {
// implementar logica aqui
let soma = 0;
for (let i = 0; i < value.length; i++) {
if (value[i] % 2 == 0) {
soma += value[i];
}
}
return soma;
}

View File

@ -1,4 +1,13 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
let array = word1.toLowerCase().split('').sort();
let array2 = word2.toLowerCase().split('').sort();
if (word1.length !== word2.length) {
return false;
} else {
if (array.toString() === array2.toString()) {
return true;
} else return false;
}
}

View File

@ -1,4 +1,15 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
const value = text.toLocaleLowerCase().split("").sort();
let counts = {};
value.forEach(function (x) {
counts[x] = (counts[x] || 0) + 1;
});
const maior = Object.keys(counts).sort(function (a, b) {
return counts[a] > counts[b] ? -1 : counts[b] > counts[a] ? 1 : 0;
})[0];
return maior;
}

View File

@ -1,4 +1,13 @@
export function longestWords(words) {
// implementar logica aqui
let maior = "";
for (const string of words) {
if (string.length > maior.length) {
maior = string;
}
}
const maiores = words.filter((string) => string.length === maior.length);
return maiores;
}