feature/algoritimos #1

Merged
RamonDiasFerreira merged 11 commits from feature/algoritimos into master 2022-11-02 19:48:31 +00:00
10 changed files with 75 additions and 13 deletions

View File

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

View File

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

View File

@ -1,4 +1,8 @@
export function maxValue(values) { export function maxValue(values) {
// implementar logica aqui // implementar logica aqui
if(values.length === 0){
return 0
} else {
return Math.max(...values)
}
} }

View File

@ -1,4 +1,25 @@
export function fibonacci(value) { export function fibonacci(value) {
// implementar logica aqui // implementar logica aqui
if(value < 1) return 0
if(value <=2) return 1
let fibMin2 = 0
let fibMin1 = 1
let fibValue = value
for(let i = 2; i <= value; i++) {
fibValue = fibMin1 + fibMin2
fibMin2 = fibMin1
fibMin1 = fibValue
}
return fibValue
// Forma inicial pensada, mas demorava muito tempo para passar nos testes.
// if(value === 0) {
// return 0
// }
// else if (value <= 2) {
// return 1
// }
// return fibonacci(value - 1) + fibonacci(value - 2);
} }

View File

@ -1,4 +1,6 @@
export function isPrime(value) { export function isPrime(value) {
// implementar logica aqui // implementar logica aqui
var start = 2;
while (start <= Math.sqrt(value)) if (value % start++ < 1) return false;
return value > 1;
} }

View File

@ -1,4 +1,8 @@
export function sum(values) { export function sum(values) {
// implementar logica aqui // implementar logica aqui
let soma = 0
for(let i in values) {
soma += values[i]
}
return soma
} }

View File

@ -1,4 +1,11 @@
export function sumEven(value) { export function sumEven(value) {
// implementar logica aqui // implementar logica aqui
var retorno = value.filter(pares => (pares %2)== 0);
} let soma = 0
for(let i in retorno) {
soma += retorno[i]
}
return soma
}

View File

@ -1,4 +1,13 @@
export function isAnagram(word1, word2) { export function isAnagram(word1, word2) {
// implementar logica aqui // implementar logica aqui
let word1Lower = word1.toLowerCase()
} let word2Lower = word2.toLowerCase()
if (word1Lower.length !== word2Lower.length) {
return false;
}
var string1 = word1Lower.split('').sort().join('');
var string2 = word2Lower.split('').sort().join('');
var result = (string1 === string2);
return result;
}

View File

@ -1,4 +1,11 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui let max = 0,
return "" 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,11 @@
export function longestWords(words) { export function longestWords(words) {
// implementar logica aqui // implementar logica aqui
let longest = '';
} for (let word of words) {
if (word.length > longest.length) {
longest = word;
}
}
return words.filter((word) => word.length === longest.length);
}