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

Reviewed-on: #1
This commit is contained in:
Andrea Matsunaga 2022-11-01 17:21:35 +00:00
commit afd61b3eae
10 changed files with 67 additions and 18 deletions

View File

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

View File

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

View File

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

View File

@ -1,4 +1,15 @@
export function fibonacci(value) {
// implementar logica aqui
let beforeLastNumber = 0;
let lastNumber = 1;
let nextNumber;
if (value < 2) return value;
for (let i = 2; i <= value; i++) {
nextNumber = lastNumber + beforeLastNumber;
beforeLastNumber = lastNumber;
lastNumber = nextNumber;
}
return lastNumber;
}

View File

@ -1,4 +1,10 @@
export function isPrime(value) {
// implementar logica aqui
if (value <= 1) return false;
for (let divisor = 2; divisor <= Math.sqrt(value); divisor++) {
if (value % divisor === 0) {
return false
}
}
return true
}

View File

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

View File

@ -1,4 +1,10 @@
export function sumEven(value) {
// implementar logica aqui
let sum = 0;
for (let number of value) {
if(number % 2 === 0) {
sum += number;
}
}
return sum;
}

View File

@ -1,4 +1,8 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
if (word1.length != word2.length) return false
let sortedWord1Array = [...word1.toLowerCase()].sort()
let sortedWord2Array = [...word2.toLowerCase()].sort()
return (sortedWord1Array.join('') === sortedWord2Array.join(''));
}

View File

@ -1,4 +1,18 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
let charObj = {};
let maxCount = 0;
let maxChar = "";
for (let char of text) {
charObj[char] = ++charObj[char] || 1;
}
for (let char in charObj) {
if (charObj[char] > maxCount) {
maxCount = charObj[char];
maxChar = char;
}
}
return maxChar;
}

View File

@ -1,4 +1,13 @@
export function longestWords(words) {
// implementar logica aqui
let sortedWords = words.sort((a, b) => b.length - a.length);
let maxLength = sortedWords[0].length
let longestWords = []
for (let word of sortedWords) {
if(word.length != maxLength) break;
longestWords.push(word)
}
return longestWords;
}