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

Reviewed-on: #1
This commit is contained in:
Caroline Moran 2022-10-28 13:25:52 +00:00
commit e5b6762c0d
10 changed files with 97 additions and 22 deletions

View File

@ -1,4 +1,4 @@
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
}
export function triangleArea(base, height) {
return (base * height) / 2;
}

View File

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

View File

@ -1,4 +1,18 @@
export function fibonacci(value) {
// implementar logica aqui
}
let penultimo = 0,
ultimo = 1;
let numero;
let arr = [];
if (value < 2) {
return value;
} else {
for (let count = 2; count <= value; count++) {
numero = ultimo + penultimo;
penultimo = ultimo;
ultimo = numero;
arr.push(ultimo);
}
return arr[value - 2];
}
}

View File

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

View File

@ -1,4 +1,8 @@
export function sum(values) {
// implementar logica aqui
}
function add(a, b) {
return a + b;
}
var soma = values.reduce(add, 0);
return soma;
}

View File

@ -1,4 +1,15 @@
export function sumEven(value) {
// implementar logica aqui
}
const arr = [];
for (let index = 0; index < value.length; index++) {
const element = value[index];
if (element % 2 == 0) {
arr.push(element);
}
}
function add(a, b) {
return a + b;
}
var soma = arr.reduce(add, 0);
return soma;
}

View File

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

View File

@ -1,4 +1,10 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
}
// implementar logica aqui
let textLower = text.toLowerCase().split("").sort();
for (let index = 1; index < textLower.length; index++) {
textLower = textLower.filter((e, i, a) => a.indexOf(e) !== i);
}
let letter = [...new Set(textLower)];
return letter.join("");
}

View File

@ -1,4 +1,17 @@
export function longestWords(words) {
// implementar logica aqui
}
// implementar logica aqui
let max_string_size = 0;
let big_string_list = [];
for (let string of words) {
const string_size = string.length;
if (string_size > max_string_size) {
big_string_list = [string];
max_string_size = string_size;
} else if (string_size == max_string_size) {
big_string_list.push(string);
}
}
return big_string_list;
}