feature/algoritmo #11

Merged
ManuelaLuanaSchumackerTavares merged 21 commits from feature/algoritmo into master 2022-10-31 17:24:28 +00:00
10 changed files with 94 additions and 9 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,10 @@
export function maxValue(values) {
// implementar logica aqui
if(values.length == 1){
return values[i];
}else if(values.length == []){
return 0;
}else{
return Math.max.apply(null, values);
}
}

View File

@ -1,4 +1,19 @@
export function fibonacci(value) {
// implementar logica aqui
if(value == 0){
return value;
}
let firstValue = 0, secondValue = 1, thirdValue =1;
for(let i = 2; i <= value; i++){
thirdValue = firstValue + secondValue;
firstValue = secondValue;
secondValue = thirdValue;
}
return thirdValue;
// if(value < 2){
// value = value;
// }else{
// value = fibonacci(value - 1) + fibonacci(value - 2);
// }
// return value;
}

View File

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

View File

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

View File

@ -1,4 +1,10 @@
export function sumEven(value) {
// implementar logica aqui
let somaPar = 0;
for(let i = 0; i < value.length; i++){
if(value[i] % 2 == 0){
somaPar += value[i];
}
}
return somaPar;
}

View File

@ -1,4 +1,11 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
const palavra = str =>
str
.toLowerCase()
.replace(/[^a-z0-9]/, '')
.split('')
.sort()
.join('');
return palavra(word1) === palavra(word2);
}

View File

@ -1,4 +1,12 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
let letraRepetida;
let str = text.toLowerCase().replace(/\,*\s/g, "").split("", text.length);
for(let i = 0; i < text.length; i++){
for(let maisRepetida = i + 1; maisRepetida < text.length; maisRepetida++){
letraRepetida = str[i];
}
}
return letraRepetida;
}

View File

@ -1,4 +1,30 @@
export function longestWords(words) {
// implementar logica aqui
if(words.length == 0 || words.length == 1) {
return words;
}else{
words.sort((a, b) => {
if(a.length > b.length){
return -1;
}else if(a.length < b.length){
return 1;
}else{
return 0;
}
});
let wordTaker = [];
let firstWord = words[0].length;
for (let i = 0; i < words.length; i++) {
const element = words[i];
if(element.length == firstWord){
wordTaker.push(element);
}else{
break;
}
}
return wordTaker;
}
}