forked from M3-Academy/challenge-algorithms-v2.0
Merge pull request 'development' (#1) from development into master
Reviewed-on: #1
This commit is contained in:
commit
afd61b3eae
@ -1,4 +1,3 @@
|
||||
export function greet(name) {
|
||||
// implementar logica aqui
|
||||
return "";
|
||||
return `Hello ${name}`;
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
export function triangleArea(base, height) {
|
||||
// your code here
|
||||
return base * height /2;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
export function maxValue(values) {
|
||||
// implementar logica aqui
|
||||
|
||||
if(values.length < 1) return 0;
|
||||
return Math.max(...values);
|
||||
}
|
@ -1,4 +1,15 @@
|
||||
export function fibonacci(value) {
|
||||
// implementar logica aqui
|
||||
let beforeLastNumber = 0;
|
||||
let lastNumber = 1;
|
||||
let nextNumber;
|
||||
|
||||
if (value < 2) return value;
|
||||
|
||||
for (let i = 2; i <= value; i++) {
|
||||
nextNumber = lastNumber + beforeLastNumber;
|
||||
beforeLastNumber = lastNumber;
|
||||
lastNumber = nextNumber;
|
||||
}
|
||||
|
||||
return lastNumber;
|
||||
}
|
@ -1,4 +1,10 @@
|
||||
export function isPrime(value) {
|
||||
// implementar logica aqui
|
||||
|
||||
if (value <= 1) return false;
|
||||
|
||||
for (let divisor = 2; divisor <= Math.sqrt(value); divisor++) {
|
||||
if (value % divisor === 0) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
export function sum(values) {
|
||||
// implementar logica aqui
|
||||
|
||||
if(values.length < 1) return 0;
|
||||
return values.reduce((previousValue, currentValue) => previousValue + currentValue);
|
||||
}
|
@ -1,4 +1,10 @@
|
||||
export function sumEven(value) {
|
||||
// implementar logica aqui
|
||||
|
||||
let sum = 0;
|
||||
|
||||
for (let number of value) {
|
||||
if(number % 2 === 0) {
|
||||
sum += number;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
export function isAnagram(word1, word2) {
|
||||
// implementar logica aqui
|
||||
|
||||
if (word1.length != word2.length) return false
|
||||
|
||||
let sortedWord1Array = [...word1.toLowerCase()].sort()
|
||||
let sortedWord2Array = [...word2.toLowerCase()].sort()
|
||||
|
||||
return (sortedWord1Array.join('') === sortedWord2Array.join(''));
|
||||
}
|
@ -1,4 +1,18 @@
|
||||
export function mostUsedChar(text) {
|
||||
// implementar logica aqui
|
||||
return ""
|
||||
let charObj = {};
|
||||
let maxCount = 0;
|
||||
let maxChar = "";
|
||||
|
||||
for (let char of text) {
|
||||
charObj[char] = ++charObj[char] || 1;
|
||||
}
|
||||
|
||||
for (let char in charObj) {
|
||||
if (charObj[char] > maxCount) {
|
||||
maxCount = charObj[char];
|
||||
maxChar = char;
|
||||
}
|
||||
}
|
||||
|
||||
return maxChar;
|
||||
}
|
@ -1,4 +1,13 @@
|
||||
export function longestWords(words) {
|
||||
// implementar logica aqui
|
||||
|
||||
|
||||
let sortedWords = words.sort((a, b) => b.length - a.length);
|
||||
let maxLength = sortedWords[0].length
|
||||
let longestWords = []
|
||||
|
||||
for (let word of sortedWords) {
|
||||
if(word.length != maxLength) break;
|
||||
longestWords.push(word)
|
||||
}
|
||||
|
||||
return longestWords;
|
||||
}
|
Loading…
Reference in New Issue
Block a user