Merge pull request 'development' (#13) from development into master

Reviewed-on: #13
This commit is contained in:
Rafael Sampaio de Oliveira 2022-11-01 16:32:58 +00:00
commit 3e098ff972
10 changed files with 71 additions and 21 deletions

View File

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

View File

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

View File

@ -1,4 +1,12 @@
export function maxValue(values) { export function maxValue(values) {
// implementar logica aqui // implementar logica aqui
let max = values.reduce(function (a, b) {
return Math.max(a, b);
}, -Infinity);
if (values.length === 0) {
return 0;
} else {
return max;
}
} }

View File

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

View File

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

View File

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

View File

@ -1,4 +1,15 @@
export function sumEven(value) { export function sumEven(value) {
// implementar logica aqui // implementar logica aqui
let pair = (x) => x % 2 === 0;
if (value.length === 0) {
return 0;
} else if (value % 2 === 1) {
return 0;
} else {
let sumOfPairs = value
.filter(pair)
.reduce((pairs, number) => pairs + number);
return sumOfPairs;
}
} }

View File

@ -1,4 +1,11 @@
export function isAnagram(word1, word2) { export function isAnagram(word1, word2) {
// implementar logica aqui // implementar logica aqui
let str1 = word1.toLowerCase().split("").sort().join("");
let str2 = word2.toLowerCase().split("").sort().join("");
if (str1 === str2) {
return true;
} else {
return false;
}
} }

View File

@ -1,4 +1,17 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui // implementar logica aqui
return "" let arr = text.toLowerCase().split("").sort();
let mostRepeated = null;
let moreOccurrences = -1;
let count = 1;
for (let i = 1; i <= arr.length; i++) {
if (i < arr.length && arr[i] === arr[i - count]) {
count++;
} else if (count > moreOccurrences) {
mostRepeated = arr[i - 1];
moreOccurrences = count;
}
}
return `${mostRepeated}`;
} }

View File

@ -1,4 +1,5 @@
export function longestWords(words) { export function longestWords(words) {
// implementar logica aqui // implementar logica aqui
let maxLength = Math.max(...words.map((e) => e.length));
return words.filter((e) => e.length === maxLength);
} }