Merge pull request 'development' (#11) from development into master

Reviewed-on: #11
This commit is contained in:
Savio Carvalho Moraes 2022-10-30 18:40:05 +00:00
commit 97fb92c06a
13 changed files with 158 additions and 69 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 let area = (base * height) / 2;
return area;
} }

View File

@ -1,4 +1,13 @@
export function maxValue(values) { export function maxValue(values) {
// implementar logica aqui let max = values[0];
if (values.length === 0) {
return 0;
} else {
for (let index = 0; index <= values.length; index++) {
if (max < values[index]) {
max = values[index];
}
}
return max;
}
} }

View File

@ -1,4 +1,15 @@
export function fibonacci(value) { export function fibonacci(value) {
// implementar logica aqui let vet = [];
vet.push(0);
vet.push(1);
if (value == 0) {
return vet[0];
} else if (value == 1) {
return vet[1];
} else {
for (let index = 2; index <= value; index++) {
vet[index] = vet[index - 2] + vet[index - 1];
}
}
return vet.at(-1);
} }

View File

@ -1,39 +1,39 @@
import { fibonacci } from "." import { fibonacci } from ".";
describe('fibonacci', () => { describe("fibonacci", () => {
it('Dever retornar 0 quando passamos o valor 0', () => { it("Dever retornar 0 quando passamos o valor 0", () => {
expect(fibonacci(0)).toBe(0) expect(fibonacci(0)).toBe(0);
}) });
it('Dever retornar 1 quando passamos o valor 1', () => { it("Dever retornar 1 quando passamos o valor 1", () => {
expect(fibonacci(1)).toBe(1) expect(fibonacci(1)).toBe(1);
}) });
it('Dever retornar 1 quando passamos o valor 2', () => { it("Dever retornar 1 quando passamos o valor 2", () => {
expect(fibonacci(2)).toBe(1) expect(fibonacci(2)).toBe(1);
}) });
it('Dever retornar 2 quando passamos o valor 3', () => { it("Dever retornar 2 quando passamos o valor 3", () => {
expect(fibonacci(3)).toBe(2) expect(fibonacci(3)).toBe(2);
}) });
it('Dever retornar 3 quando passamos o valor 4', () => { it("Dever retornar 3 quando passamos o valor 4", () => {
expect(fibonacci(4)).toBe(3) expect(fibonacci(4)).toBe(3);
}) });
it('Dever retornar 5 quando passamos o valor 5', () => { it("Dever retornar 5 quando passamos o valor 5", () => {
expect(fibonacci(5)).toBe(5) expect(fibonacci(5)).toBe(5);
}) });
it('deve retonar 8 quando passamos o valor 6', () => { it("deve retonar 8 quando passamos o valor 6", () => {
expect(fibonacci(6)).toBe(8) expect(fibonacci(6)).toBe(8);
}) });
it('Dever retornar 9227465 quando passamos o valor 35', () => { it("Dever retornar 9227465 quando passamos o valor 35", () => {
expect(fibonacci(35)).toBe(9227465) expect(fibonacci(35)).toBe(9227465);
}) });
it('Dever retornar 1836311903 quando passamos o valor 46', () => { it("Dever retornar 1836311903 quando passamos o valor 46", () => {
expect(fibonacci(46)).toBe(1836311903) expect(fibonacci(46)).toBe(1836311903);
}) });
}) });

View File

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

View File

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

View File

@ -5,7 +5,7 @@ Faça um algoritmo que retorne a soma de todos os números de um array
## Exemplo ## Exemplo
```js ```js
sum([1, 2, 3, 4, 5]) // 15 sum([1, 2, 3, 4, 5]); // 15
sum([10, 10, 10, 10]) // 40 sum([10, 10, 10, 10]); // 40
sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) // 55 sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // 55
``` ```

View File

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

View File

@ -1,4 +1,22 @@
export function isAnagram(word1, word2) { export function isAnagram(word1, word2) {
// implementar logica aqui let word1Lower = Array.from(word1.toLowerCase());
let word2Lower = Array.from(word2.toLowerCase());
if (word1Lower.length !== word2Lower.length) {
return false;
}
let contador = 0;
while (word1.length !== contador) {
let letraword2 = word2Lower[0];
if (word1Lower.indexOf(letraword2) !== -1) {
let indice = word1Lower.indexOf(letraword2);
word1Lower.splice(indice, 1);
word2Lower.shift();
}
contador = contador + 1;
}
if (word1Lower.length === 0 && word2Lower.length === 0) {
return true;
} else {
return false;
}
} }

View File

@ -5,9 +5,7 @@ Faça um algoritmo que retorne se um palavra é anagram da outra
## Exemplo ## Exemplo
```js ```js
isAnagram("roma", "amor"); // true
isAnagram('roma', 'amor') // true isAnagram("roma", "amora"); // false
isAnagram('roma', 'amora') // false isAnagram("roma", "amora"); // false
isAnagram('roma', 'amora') // false
``` ```

View File

@ -1,4 +1,28 @@
export function mostUsedChar(text) { export function mostUsedChar(text) {
// implementar logica aqui let vetChar = [];
return "" let qtdCharAtual = 0;
let charAtual = "";
let qtdCharMaior = 0;
let charMaior = "";
for (let index = 0; index < text.length; index++) {
const element = text[index];
if (!vetChar.includes(element)) {
vetChar.push(element);
}
}
for (let chave = 0; chave <= vetChar.length; chave++) {
charAtual = vetChar[chave];
qtdCharAtual = 0;
for (let index = 0; index <= text.length; index++) {
if (vetChar[chave] === text[index]) {
qtdCharAtual = qtdCharAtual + 1;
}
if (qtdCharMaior < qtdCharAtual && vetChar[chave] !== text[index]) {
charMaior = charAtual;
qtdCharMaior = qtdCharAtual;
}
}
}
return charMaior;
} }

View File

@ -1,4 +1,15 @@
export function longestWords(words) { export function longestWords(words) {
// implementar logica aqui let vetWords = [];
for (let index = 0; index < words.length; index++) {
if (vetWords.length === 0) {
vetWords.push(words[index]);
} else if (vetWords[0].length < words[index].length) {
vetWords = [];
vetWords.push(words[index]);
} else if (vetWords[0].length === words[index].length) {
vetWords.push(words[index]);
}
}
return vetWords;
} }