feature/algoritmos #1

Merged
LeonardoPereiraRocha merged 10 commits from feature/algoritmos into master 2022-11-02 20:24:57 +00:00
10 changed files with 95 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,5 @@
export function triangleArea(base, height) {
// your code here
let result;
result = (base * height) / 2;
return result;
}

View File

@ -1,4 +1,15 @@
export function maxValue(values) {
// implementar logica aqui
let max = 0;
max = values[0];
if (values.length === 0){
return 0;
}
for(let i= 0; i < values.length; i++) {
if (values[i] > max) {
max = values[i];
}
}
return max;
}

View File

@ -1,4 +1,14 @@
export function fibonacci(value) {
// implementar logica aqui
//
let previous = 0;
let sum = 0;
let next = 1;
for (let i = 0; i < value; i++) {
sum = previous + next;
previous = next;
next = sum;
}
return previous;
}

View File

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

View File

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

View File

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

View File

@ -1,4 +1,19 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
let testWord1;
let testWord2;
if (word1.length !== word2.length) {
return false;
}
testWord1 = word1.toLowerCase('').split('').sort().join('');
testWord2 = word2.toLowerCase('').split('').sort().join('');
if (testWord1 === testWord2) {
return true;
}
return false;
}

View File

@ -1,4 +1,19 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
let arrChar;
arrChar = text.split('');
let countCharMax = 1;
let countChar = 0;
let char;
for (let i=0; i<arrChar.length; i++)
{
for (let j=i; j<arrChar.length; j++) {
if (arrChar[i] == arrChar[j])
countChar++;
if (countCharMax<countChar) {
countCharMax=countChar;
char = arrChar[i];
}
}
countChar = 0;
} return char;
}

View File

@ -1,4 +1,10 @@
export function longestWords(words) {
// implementar logica aqui
let longWord = "";
let word;
for(word of words) {
if (word.length > longWord.length){
longWord = word;
}
}
return words.filter((word) => word.length === longWord.length);
}