Entrega do Desafio #1

Merged
anacarolinaduartecavalcante merged 12 commits from feature/10-longestWords into master 2022-10-28 12:14:06 +00:00
10 changed files with 50 additions and 9 deletions

View File

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

View File

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

View File

@ -1,4 +1,12 @@
export function maxValue(values) {
// implementar logica aqui
if (values.length) {
let max = -Infinity;
for (let num of values) {
max = num > max ? num : max;
}
return max;
}
return 0;
}

View File

@ -1,4 +1,5 @@
export function fibonacci(value) {
// implementar logica aqui
var sqrt5 = Math.sqrt(5);
return Math.round(Math.pow(((1 + sqrt5) / 2), value) / sqrt5);
}

View File

@ -1,4 +1,8 @@
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,8 @@
export function sum(values) {
// implementar logica aqui
let sumOfArrays = 0;
for(let index = 0; index < values.length; index +=1) {
sumOfArrays = sumOfArrays + values[index];
}
return sumOfArrays;
}

View File

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

View File

@ -1,4 +1,11 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
const Anagram = str =>
str
.toLowerCase()
.replace(/[^a-z0-9]/gi, '')
.split('')
.sort()
.join('');
return Anagram(word1) === Anagram(word2);
}

View File

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

View File

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