Merge branch 'feature/challenge-algorithms'

This commit is contained in:
Saulo Klein Nery 2022-10-28 13:10:46 -03:00
commit b19d65ac48
10 changed files with 84 additions and 6 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,17 @@
export function maxValue(values) {
// implementar logica aqui
let maior = 0;
values.map(
(element, i) => {
if(i === 0)
maior = element;
if(element > maior)
maior = element;
}
);
return maior;
}

View File

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

View File

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

View File

@ -1,4 +1,12 @@
export function sum(values) {
// implementar logica aqui
let soma = 0;
values.map(
(element) => {
soma += element;
}
);
return soma;
}

View File

@ -1,4 +1,12 @@
export function sumEven(value) {
// implementar logica aqui
let soma = 0;
value.map(
(element) => {
if(element % 2 === 0)
soma += element;
}
);
return soma;
}

View File

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

View File

@ -1,4 +1,15 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
text.trim().toLowerCase();
let bigger = 0;
let mostUsed = '';
for(const char of text){
if(text.split(char).length > bigger){
bigger = text.split(char).length;
mostUsed = char;
}
}
return mostUsed;
}

View File

@ -1,4 +1,19 @@
export function longestWords(words) {
// implementar logica aqui
let longWords = [];
let longLength = 0;
words.map(
(word) => {
if(word.length > longLength){
longLength = word.length;
longWords.splice(0, longWords.length);
longWords.push(word);
}
else if(word.length === longLength)
longWords.push(word);
}
);
return longWords;
}