forked from M3-Academy/challenge-algorithms-v2.0
Merge pull request 'Develop' (#1) from Develop into master
Reviewed-on: #1
This commit is contained in:
commit
9a5eda2994
@ -1,4 +1,4 @@
|
||||
export function greet(name) {
|
||||
// implementar logica aqui
|
||||
return "";
|
||||
return `Hello ${name}`;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
export function triangleArea(base, height) {
|
||||
// your code here
|
||||
return base * height /2
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
export function maxValue(values) {
|
||||
// implementar logica aqui
|
||||
|
||||
if (values.length == 0){
|
||||
return 0
|
||||
}else{
|
||||
return Math.max(...values)
|
||||
}
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
export function fibonacci(value) {
|
||||
// implementar logica aqui
|
||||
|
||||
const fibo = [0, 1]
|
||||
for (let i = 2; i <= value; i++) {
|
||||
fibo[i] = fibo[i-1] + fibo[i-2]
|
||||
}
|
||||
return fibo[value]
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
export function isPrime(value) {
|
||||
// implementar logica aqui
|
||||
|
||||
for (let div = 2; div < value; div++)
|
||||
if (value % div == 0) return false;
|
||||
return true;
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
export function sum(values) {
|
||||
// implementar logica aqui
|
||||
|
||||
let sums = 0;
|
||||
values.forEach(item => sums += item);
|
||||
return sums
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
export function sumEven(value) {
|
||||
// implementar logica aqui
|
||||
|
||||
let sums = 0;
|
||||
value.forEach(item => {
|
||||
if(item%2==0) sums += item;});
|
||||
return sums
|
||||
}
|
@ -1,4 +1,14 @@
|
||||
export function isAnagram(word1, word2) {
|
||||
// implementar logica aqui
|
||||
|
||||
if(word1.length == word2.length){
|
||||
const words1 = word1.toUpperCase().split("").sort();
|
||||
const words2 = word2.toUpperCase().split("").sort();
|
||||
if (words1.join() == words2.join()){
|
||||
return true
|
||||
}else {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
@ -1,4 +1,9 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
let words = {}
|
||||
const texts = text.toLowerCase().split("").sort();
|
||||
texts.forEach((word) => words[word] = (words[word] || 0) + 1);
|
||||
const maxVal = Math.max(...Object.values(words));
|
||||
const word = Object.keys(words).find((key) => words[key] === maxVal);
|
||||
return word
|
||||
}
|
@ -1,4 +1,10 @@
|
||||
export function longestWords(words) {
|
||||
// implementar logica aqui
|
||||
|
||||
let longestSize = 0
|
||||
let longestWord = []
|
||||
words.forEach(element => {
|
||||
if(element.length>longestSize)
|
||||
{longestSize = element.length}})
|
||||
longestWord = words.filter(element => element.length === longestSize);
|
||||
return longestWord
|
||||
}
|
Loading…
Reference in New Issue
Block a user