Skip to content

[Section 4] - Sobe exercícios #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4608280
adiciona exercioc 2
devcarolzita Oct 28, 2022
5e145b5
Criado index para pasta
devcarolzita Apr 22, 2022
f0e398f
Ajuste de only para describe
devcarolzita Apr 22, 2022
3713b98
Ajuste de nome
devcarolzita Apr 22, 2022
9a36cf4
Ajuste de texto
devcarolzita Apr 22, 2022
ce0ab6d
Adiciona teste de formatação de telefone
lucaslealdev May 16, 2022
0162a21
corrige-operadores-aritmeticos
mottak May 30, 2022
8f9972d
Update desafio-operadores-aritmeticos-08.js
mottak May 30, 2022
58a2dee
Update Desafios/Operadores Aritméticos/desafio-operadores-aritmeticos…
mottak May 30, 2022
777f86a
fix: primeiro teste de destructuring e hofs
cpwaldow Sep 12, 2022
ef55198
add correctly object values
cpwaldow Sep 12, 2022
6dcd5bd
fix: add typeof to expect arg and fix letter to string
cpwaldow Sep 12, 2022
91b8faf
fix: change typeof to boolean if is array
cpwaldow Sep 12, 2022
cba30f8
fix: add typeof to test and add const to gabarito
cpwaldow Sep 12, 2022
cb9e434
fix: array validation
cpwaldow Sep 12, 2022
94365b6
feat: update challenge 05 functions, test and rubric
cpwaldow Sep 19, 2022
95995bf
update rubric
cpwaldow Sep 19, 2022
90c94ec
update param name
cpwaldow Sep 19, 2022
727f280
update rubric
cpwaldow Sep 19, 2022
3471b83
fix: fix wrong function name export
cpwaldow Sep 19, 2022
f9bb3a2
fix: add params to function
cpwaldow Sep 19, 2022
355d7f0
remove console.log
cpwaldow Sep 19, 2022
f69f20b
fix imc test
cpwaldow Sep 21, 2022
d2ed26d
fix: import right function to test fahrenheitToCelsius
cpwaldow Sep 21, 2022
460e691
fix: multiple functions in sequence
cpwaldow Sep 21, 2022
6c37715
fix: rename function param
cpwaldow Sep 21, 2022
cbcbd64
fix: rename function param
cpwaldow Sep 21, 2022
3f9df50
fix: rename function param
cpwaldow Sep 21, 2022
c3e3d57
Update Desafios/Estruturas Condicionais/Gabaritos/1-10.js
cpwaldow Sep 21, 2022
49a6919
Update Desafios/Estruturas Condicionais/Gabaritos/1-10.js
cpwaldow Sep 21, 2022
cf3c8b3
Apply suggestions from code review
cpwaldow Sep 21, 2022
a4a8fe8
Apply suggestions from code review
cpwaldow Sep 21, 2022
18e5427
Apply suggestions from code review
cpwaldow Sep 21, 2022
7461101
Correção enunciado desafio-strings-03
marciodanielll Oct 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Desafios/Arrays/desafio-arrays-01.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ Escreva um algoritmo que recebe um array de números inteiros, procure o maior v
*/

function getMaxNumber(numbers) {
// Desenvolva seu código nessa função
return // Retorne o resultado aqui
let number = numbers[0];
let maiorNumero;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sugestão, podemos complementar a variável?

for (let index = 0; index < numbers.length; index++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Será que possui alguma melhor prática que tal testar com index += 1

const element = numbers[index];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verificar o const dentro do for

if(numbers[index] > number){
number = numbers[index]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poderia comentar este if explicando sua funcionalidade?

}
}
return number;
}

console.log(getMaxNumber([ 2,34,5,1,2]));

module.exports = getMaxNumber;
10 changes: 9 additions & 1 deletion Desafios/Arrays/desafio-arrays-02.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ Escreva um algoritmo que recebe um array de números inteiros, procure o menor v
*/

function getMinNumber(numbers) {
let teste;
let n = numbers[0];
for (const number of numbers) {
if(numbers[number] < n){
n = numbers[number]
}
}
// Desenvolva seu código nessa função
return // Retorne o resultado aqui
return n;
}

console.log(getMinNumber([24,15,14,13,44,1,44,55]))
module.exports = getMinNumber;
6 changes: 4 additions & 2 deletions Desafios/Desafiadores/Gabaritos/11-16.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function fibonnaci(n) {
return fib[n - 1];
}

/* 14 - Soma de números primos */
function isPrimo(number) {
if (number <= 1) return false;

Expand All @@ -62,7 +63,6 @@ function isPrimo(number) {
return true;
}

/* 14 - Soma de números primos */
function sumPrimesNumbers() {
let sum = 0;
for (let index = 1; index <= 150; index += 1) {
Expand Down Expand Up @@ -95,6 +95,8 @@ function meanFactorialFromAToB(a, b) {
return parseFloat((sum / (b - a + 1)).toFixed(2));
}

/* 16 - Validação de CPF */

function calcCpfFirstDigit(cpfArray) {
const sum = cpfArray
.slice(0, 9)
Expand All @@ -116,7 +118,7 @@ function calcCpfSecondDigit(cpfArray) {
return rest;
}

/* 16 - Validação de CPF */

function cpfValidator(cpf) {
const cpfArray = cpf
.replace(/[^0-9]/g, "")
Expand Down
2 changes: 1 addition & 1 deletion Desafios/Desafiadores/desafiador-011.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Saída:

*/

function musicalNotes3(notes){
function musicalNotes3(arrNotes){
// Desenvolva seu código nessa função
}

Expand Down
8 changes: 4 additions & 4 deletions Desafios/Destructuring e HOFs/Gabaritos/1-6.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ const getBandsName = () => {
// 4 - Filtre e retorne um array apenas com o nome das bandas que são dos Estados Unidos

const usaFilter = () => {
usaBands = data.bands.filter((band) => band.country = 'United States')
const usaBands = data.bands.filter((band) => band.country = 'United States')
.map(({ bandName }) => bandName);

return usaBands;
}

// 5 - Filtre e retorne um array com as informações das bandas que contenham 'Rock' no gênero musical
// 5 - Filtre e retorne um array com os nomes das bandas que contenham 'Rock' no gênero musical

const rockFilter = () => {
const bandsGenre = data.bands.filter((band) => band.genre.includes('Rock'));

const bandsGenre = data.bands.filter((band) => band.genre.includes('Rock')).map(band => band.bandName)
return bandsGenre;
}

// 6 - Filtre e retorne um array com todos os álbuns que possuem nota igual a 100
Expand Down
2 changes: 1 addition & 1 deletion Desafios/Destructuring e HOFs/desafio-hofs-05.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const data = require('./data');

// 5 - Filtre e retorne um array com as informações das bandas que contenham 'Rock' no gênero musical
// 5 - Filtre e retorne um array com os nomes das bandas que contenham 'Rock' no gênero musical

const rockFilter = () => {

Expand Down
15 changes: 15 additions & 0 deletions Desafios/Destructuring e HOFs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const getBandsInformation = require('./desafio-hofs-01.js');
const getBestAlbuns = require('./desafio-hofs-02.js');
const getBandsName = require('./desafio-hofs-03.js');
const usaFilter = require('./desafio-hofs-04.js');
const rockFilter = require('./desafio-hofs-05.js');
const highestRatingFilter = require('./desafio-hofs-06.js');

module.exports = {
getBandsInformation,
getBestAlbuns,
getBandsName,
usaFilter,
rockFilter,
highestRatingFilter
};
10 changes: 5 additions & 5 deletions Desafios/Estruturas Condicionais/Gabaritos/1-10.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ function robotFriend(mon, dad, me, brother, sister) {
}

/* 06 - Taxa Metabólica Basal */
function basalMetabolicRate(age, sex, weight, heigh) {
let bmr;
function basalMetabolicRate(age, sex, weight, height) {
let metabolicRate;

if (sex === "M") {
bmr = heigh * 6.25 + weight * 9.99 - age * 4.92 + 5;
metabolicRate = height * 6.25 + weight * 9.99 - age * 4.92 + 5;
}

if (sex === "F") {
bmr = heigh * 6.25 + weight * 9.99 - age * 4.92 - 161;
metabolicRate = height * 6.25 + weight * 9.99 - age * 4.92 - 161;
}

return `A taxa metabólica basal é: ${bmr} Kcal.`;
return `A taxa metabólica basal é: ${metabolicRate} Kcal.`;
}

/* 07 - Maior ou menor de idade */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Caso não encontre o elemento, retorne:

*/

function findIndexOf(){
function findIndexOf(array, element){
// Desenvolva seu código nessa função
}

Expand Down
4 changes: 2 additions & 2 deletions Desafios/Estruturas de Repetições/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const numbersDivisibleBy3 = require('./desafio-estrutura-repeticoes-05');
const oddNumbers = require('./desafio-estrutura-repeticoes-06');
const findIndexOf = require('./desafio-estrutura-repeticoes-07');
const sortDec = require('./desafio-estrutura-repeticoes-08');
const includesInArrays = require('./desafio-estrutura-repeticoes-09');
const includesArrays = require('./desafio-estrutura-repeticoes-09');

module.exports ={
encode,
Expand All @@ -17,5 +17,5 @@ module.exports ={
oddNumbers,
findIndexOf,
sortDec,
includesInArrays,
includesArrays,
}
2 changes: 0 additions & 2 deletions Desafios/Objetos/Gabaritos/1-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ function fantasyGame3(className, level) {
return `${role}, nível ${level}: ${totalLifePoints}PV, ${equipment}.`;
}

console.log(fantasyGame3("Cavaleiro", 2));

module.exports = {
fantasyGame,
fantasyGame2,
Expand Down
15 changes: 8 additions & 7 deletions Desafios/Operadores Aritméticos/Gabaritos/11-20.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/* 11 - Loja de ração */
function formatBrazilianMoney(number) {
const beforeComma = Math.floor(number);
let afterComma = Math.round(number * 100 - beforeComma * 100);
afterComma = afterComma !== 0 ? afterComma : `00`;
return `${beforeComma},${afterComma}`;
}
function paymentOptions(price) {
let inCash = price - price * 0.1;
let creditCard = price + price * 0.15;
Expand All @@ -17,12 +11,12 @@ function weightAndValue(priceKg, plateWeight) {
return `O prato de ${plateWeight} gramas custa: R$ ${totalPrice}`;
}

/* 13 - Cor aleatória */
function generateOneColor() {
let uniqueColor = Math.floor(Math.random() * 256);
return uniqueColor;
}

/* 13 - Cor aleatória */
function randomRGBColor() {
let finalColor = `rgb(${generateOneColor()}, ${generateOneColor()}, ${generateOneColor()})`;
return finalColor;
Expand Down Expand Up @@ -56,6 +50,13 @@ function randomBoolean() {
}

/* 17 - Financiamento de veículo */
function formatBrazilianMoney(number) {
const beforeComma = Math.floor(number);
let afterComma = Math.round(number * 100 - beforeComma * 100);
afterComma = afterComma !== 0 ? afterComma : `00`;
return `${beforeComma},${afterComma}`;
}

function carFinancing(carPrice, entranceValue, quota) {
let financing = carPrice - entranceValue;
let tax = 0.05;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Obs: O valor do prato tem que ter duas casas decimais após a virgula.

*/

function weightAndValue(price, gram) {
function weightAndValue(priceKg, plateWeight) {
// Desenvolva seu código nessa função
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Escreva um algoritmo que recebe a duração total de uma viagem em minutos e ret

*/

function timeTravel(minutes){
function timeTravel(totalMinutes){
// Desenvolva seu código nessa função
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Escreva o algoritmo usado por André para calcular seu próprio IMC e o retorne.

*/

function IMC(base, height){
function IMC(weight, height){
// Desenvolva seu código nessa função
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Escreva um algoritmo que recebe o valor de um prato, calcule e retorne o valor final dele acrescendo 10% de taxa por ser uma área turística e mais 5% de gorjeta para o garçon.

Obs: Retornar um valor do tipo number com duas casa decimais.
Obs2: Dependendo do método usado para arredondar o tipo da sua variável, o valor retornado pode mudar, e aqui o retorno DEVE ser do tipo NUMBER. Talvez seja preciso converter para number ao final.

*/

Expand Down
2 changes: 1 addition & 1 deletion Desafios/Operadores Aritméticos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const IMC = require('./desafio-operadores-aritmeticos-06')
const readingTime = require('./desafio-operadores-aritmeticos-07')
const restaurantExpenses = require('./desafio-operadores-aritmeticos-08')
const celsiusToFahrenheit = require('./desafio-operadores-aritmeticos-09')
const fahrenheitToCelsius = require('./desafio-operadores-aritmeticos-01')
const fahrenheitToCelsius = require('./desafio-operadores-aritmeticos-010')
const paymentOptions = require('./desafio-operadores-aritmeticos-011')
const weightAndValue = require('./desafio-operadores-aritmeticos-012')
const randomRGBColor = require('./desafio-operadores-aritmeticos-013')
Expand Down
19 changes: 19 additions & 0 deletions Desafios/Strings/Gabaritos/10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function telephoneFormat(string) {
//se não for válido retorna a própria variável
if (!string) return string;
//converte para string
if (typeof string === "number") string = string.toString();
//remove tudo que não for número
string = string.replace(/[^0-9]/g, "");
if (string.length < 10 || string.length > 11){
//se tiver menos largura que 10 ou mais de 11, é inválido
return string;
}
const regex = /^([0-9]{2})([0-9]?)([0-9]{4})([0-9]{4})$/gm;
const subst = `($1) $2 $3-$4`;
//aplica o regex de formatação e remove espaços duplicados causados
//pela possível ausência do dígito 9 antes do número
return string.replace(regex, subst).replace(' ',' ');
}

module.exports = telephoneFormat;
4 changes: 2 additions & 2 deletions Desafios/Strings/desafio-strings-03.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Entradas:
"João","Carvalho', 25

Saída:
"Meu nome é João Carvalho e tenho 25 anos de vida"
"Meu nome é João Carvalho e tenho 25 anos de vida."
---------------------------------------------------

*/

function personalPresentation(firstName, lastName, age) {
// Desenvolva seu código nessa função

}

module.exports = personalPresentation;
26 changes: 26 additions & 0 deletions Desafios/Strings/desafio-strings-10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*

10 - Telefone desconfigurado

Um banco de dados possui uma série de números de telefone, mas cada um com um padrão diferente.
Alguns têm espaço, outros não, alguns sem traço, outros não, alguns com parênteses, outros não,
e toda sorte de combinações possíveis e imagináveis.

Crie uma função que receba um número de telefone desconfigurado
e retorne o número de telefone formatado, com suporte ao dígito 9
de prefixo nos celulares, mas funcionando normalmente sem esse prefixo.

O que será avaliado?
- Ao enviar como parâmetro 11 97878-7878 a função deve retornar (11) 9 7878-7878;
- Se o parâmetro for (11)78787878 a função deve retornar (11) 7878-7878;
- Se o parâmetro for 1178787878 a função deve retornar (11) 7878-7878;
- E se não for um número de telefone válido a função deve retornar o parâmetro; logo:
- Se o parâmetro for 234 a função deve retornar 237;

*/

function telephoneFormat(string) {
// Desenvolva seu código nessa função
}

module.exports = telephoneFormat;
2 changes: 2 additions & 0 deletions Desafios/Strings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const dogName = require("./desafio-strings-06")
const includeA = require("./desafio-strings-07")
const countLetters = require("./desafio-strings-08")
const encodeMessage = require("./desafio-strings-09")
const telephoneFormat = require("./desafio-strings-10")

module.exports = {
reverseNames,
Expand All @@ -18,4 +19,5 @@ module.exports = {
includeA,
countLetters,
encodeMessage,
telephoneFormat,
}
Loading