Merge pull request 'feature/challenge-algorithms' (#1) from feature/challenge-algorithms into master

Reviewed-on: #1
This commit is contained in:
Eleonora Otz de Mendonça Soares 2022-11-01 20:41:51 +00:00
commit 4fcfb77c3a
10 changed files with 85 additions and 8 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 values = Math.max (...values)
} else {
return 0
}
} }

View File

@ -1,4 +1,22 @@
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 prev = 0
let next = 1
let result = 0
} for (let i = 2; i <= value; i++){
result = next + prev
prev = next
next = result
}
return result
}

View File

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

View File

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

View File

@ -1,4 +1,11 @@
export function sumEven(value) { export function sumEven(value) {
// implementar logica aqui // 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,11 @@
export function isAnagram(word1, word2) { export function isAnagram(word1, word2) {
// implementar logica aqui // implementar logica aqui
word1 = word1.toUpperCase().split('').sort().join('')
word2 = word2.toUpperCase().split('').sort().join('')
if(word1 === word2){
return true;
} else {
return false;
}
} }

View File

@ -1,4 +1,19 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui // implementar logica aqui
return "" let freqCounter = {}
let lcText = text.toLowerCase()
for (let char of lcText) {
freqCounter[char] = freqCounter[char] + 1 || 1;
}
let maxCount = 0;
let mostUsedChar = null;
for(let key in freqCounter) {
if(freqCounter[key] > maxCount) {
maxCount = freqCounter[key]
mostUsedChar = key
}
}
return mostUsedChar
} }

View File

@ -1,4 +1,19 @@
export function longestWords(words) { export function longestWords(words) {
// implementar logica aqui // implementar logica aqui
let longestWord = ''
words.forEach((word) => {
if(word.length > longestWord.length){
longestWord = word
}
});
const longestWords = words.filter((word) => {
if(word.length === longestWord.length){
return word
}
});
return longestWords
} }