feature/algorithms #1

Merged
naianfelix merged 10 commits from feature/algorithms into master 2022-10-28 14:00:26 +00:00
10 changed files with 63 additions and 5 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,8 @@
export function maxValue(values) {
// implementar logica aqui
if (values.length === 0) return 0;
else {
return Math.max (...values)
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,13 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
const arr = text.split("");
let timesRepeat = {};
arr.forEach((count) => {
timesRepeat[count] = (timesRepeat[count] || 0) + 1;
})
const maxVal = Math.max(...Object.values(timesRepeat));
const num = Object.keys(timesRepeat).find((key) => timesRepeat[key] === maxVal);
return num;
}

View File

@ -1,4 +1,18 @@
export function longestWords(words) {
// implementar logica aqui
let big = "";
words.forEach(word => {
if(word.length > big.length){
big = word
}
});
const result = words.filter(word => {
if(word.length === big.length){
return word
}
});
return result
}