feature/algoritmos-josecarloslins #1

Merged
josecarloslins merged 11 commits from feature/algoritmos-josecarloslins into master 2022-10-28 01:16:14 +00:00
11 changed files with 106 additions and 7 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# dependencies
/node_modules

View File

@ -1,4 +1,4 @@
export function greet(name) {
// implementar logica aqui
return "";
return `Hello ${name}`;
}

View File

@ -1,3 +1,3 @@
export function triangleArea(base, height) {
// your code here
return (base * height)/2;
}

View File

@ -1,4 +1,7 @@
export function maxValue(values) {
// implementar logica aqui
if(values.length === 0){
return 0;
}
return Math.max(...values);
}

View File

@ -1,4 +1,20 @@
export function fibonacci(value) {
// implementar logica aqui
let fibMenor1 = 0;
let fibMenor2 = 1;
let fibN = 0;
if(value < 2){
return value;
}
for (let i = 1; i <= value; i++){
fibN = fibMenor1 + fibMenor2;
fibMenor2 = fibMenor1;
fibMenor1 = fibN;
}
return fibN;
}

View File

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

View File

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

View File

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

View File

@ -1,4 +1,16 @@
export function isAnagram(word1, word2) {
// implementar logica aqui
const compare = str =>
str
.toLowerCase()
.split('')
.sort()
.join('');
if(compare(word1) === compare(word2)){
return true;
}
return false;
}

View File

@ -1,4 +1,26 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
let newStr = text.replace(' ', '').split('');
let count = 0;
let countControl = 0;
let strRepeat = '';
for(let i = 0; i < newStr.length; i++){
for(let j = 0; j < newStr.length; j++){
if(newStr[i] === newStr[j]){
count++;
}
}
if(count > countControl){
strRepeat = newStr[i];
countControl = count;
}
count = 0;
}
return strRepeat;
}

View File

@ -1,4 +1,20 @@
export function longestWords(words) {
// implementar logica aqui
let count = 0;
let strFinal = [''];
for(let i = 0; i < words.length; i++){
if(words[i].length >= strFinal[0].length){
if(strFinal[0].length === '' || strFinal[0].length < words[i].length){
strFinal.length = 0;
strFinal.push(words[i]);
}else{
strFinal.push(words[i]);
}
}
}
return strFinal;
}