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

Reviewed-on: #1
This commit is contained in:
Wellington Duarte Santos 2022-11-01 12:40:19 +00:00
commit 6eeaaf219b
10 changed files with 112 additions and 11 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,11 @@
export function maxValue(values) {
// implementar logica aqui
if(values.length < 1){
return 0;
}
let maior = Math.max.apply(null, values)
return maior;
}

View File

@ -1,4 +1,16 @@
export function fibonacci(value) {
// implementar logica aqui
var a = 0, b = 1;
if(value === 0){
return a;
}
for (var i = 2; i <= value; ++i) {
var temp = a;
a = b;
b += temp;
}
return b;
}

View File

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

View File

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

View File

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

View File

@ -1,4 +1,22 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
let test = word1.toUpperCase();
let original = word2.toUpperCase();
let tamanho1 = original.length;
let tamanho2 = test.length;
if(tamanho1 !== tamanho2){
return false;
}
let str1 = original.split('').sort().join('');
let str2 = test.split('').sort().join('');
if(str1 === str2){
return true;
}
else{
return false;
}
}

View File

@ -1,4 +1,24 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
text.toLowerCase();
let sorted = text.split('').sort().join('');
let cont = 1;
let repeatedTimes = 0;
let mostUsed = "";
for(let i = 0; i < sorted.length; i++){
if(sorted[i] === sorted[i + 1]){
cont++;
}
else{
if(cont > repeatedTimes){
repeatedTimes = cont;
mostUsed = sorted[i];
}
cont = 1;
}
}
return mostUsed;
}

View File

@ -1,4 +1,19 @@
export function longestWords(words) {
// implementar logica aqui
let maiorPalavra = 0;
let maiores = [];
for (let i = 0; i < words.length; i++){
if(words[i].length > maiorPalavra){
maiorPalavra = words[i].length
}
}
for (let i = 0; i < words.length; i++){
if(words[i].length === maiorPalavra){
maiores.push(words[i]);
}
}
return maiores;
}