diff --git "a/Parte 1 - Conceitos B\303\241sicos/Exercicio 4 - Numeros de 1 a 100.js" "b/Parte 1 - Conceitos B\303\241sicos/Exercicio 4 - Numeros de 1 a 100.js" new file mode 100644 index 0000000..f35f1f4 --- /dev/null +++ "b/Parte 1 - Conceitos B\303\241sicos/Exercicio 4 - Numeros de 1 a 100.js" @@ -0,0 +1,15 @@ +for(i = 0; 100 > i; i++) +{ + console.log(i); + + if((i) % 3 == 0 && (i) % 5 == 0) + { console.log("- FizzBuzz"); } + + else if((i) % 3 == 0) + { console.log("- Fizz"); } + + else if((i) % 5 == 0) + { console.log("- Buzz"); } + + console.log("\n"); +} \ No newline at end of file diff --git "a/Parte 1 - Conceitos B\303\241sicos/Exerc\303\255cio 2 - Xadrez.js" "b/Parte 1 - Conceitos B\303\241sicos/Exerc\303\255cio 2 - Xadrez.js" new file mode 100644 index 0000000..570dae7 --- /dev/null +++ "b/Parte 1 - Conceitos B\303\241sicos/Exerc\303\255cio 2 - Xadrez.js" @@ -0,0 +1,16 @@ +for(j = 0; j < 8; j++) +{ + for(i = 0; i < 8; i++) + { + //para cada linha + if((i + j) % 2 == 0) + { + console.log("#"); + } + else + { + console.log(" "); + } + } + console.log("\n"); +} \ No newline at end of file diff --git "a/Parte 1 - Conceitos B\303\241sicos/Exerc\303\255cio 3 - Palindromo.js" "b/Parte 1 - Conceitos B\303\241sicos/Exerc\303\255cio 3 - Palindromo.js" new file mode 100644 index 0000000..d848e0a --- /dev/null +++ "b/Parte 1 - Conceitos B\303\241sicos/Exerc\303\255cio 3 - Palindromo.js" @@ -0,0 +1,20 @@ +var palindromo = prompt("Digite um palíndromo:"); + +var tampalindromo = palindromo.length; + +var resultado = true; +//para a quantidade de linhas que o usuário quer +for(i = 0; tampalindromo > i; i++) +{ + //para cada letra + if(palindromo[i] != palindromo[tampalindromo-1]) + { + resultado = false; + break; + } + else + { tampalindromo--;} +} +if(resultado == true){ console.log("É um palíndromo. "); } + +else { console.log("Não é um palíndromo. "); } diff --git "a/Parte 1 - Conceitos B\303\241sicos/Triangulo.js" "b/Parte 1 - Conceitos B\303\241sicos/Triangulo.js" new file mode 100644 index 0000000..0a753c0 --- /dev/null +++ "b/Parte 1 - Conceitos B\303\241sicos/Triangulo.js" @@ -0,0 +1,15 @@ +var qntdelinhas = prompt("Digite um tamanho p/ o triangulo ser criado:"); + +var numporlinha=2; + +//para a quantidade de linhas que o usuário quer +for(i = 0; qntdelinhas > i; i++) +{ + //para cada linha + for(j = 0; j < numporlinha; j++) + { + console.log("#"); + } + console.log("\n"); + numporlinha++; +} diff --git "a/Parte 2 - Funcoes/Exerc\303\255cio 5 e 6 - M\303\241ximo e M\303\255nimo.js" "b/Parte 2 - Funcoes/Exerc\303\255cio 5 e 6 - M\303\241ximo e M\303\255nimo.js" new file mode 100644 index 0000000..f1a935e --- /dev/null +++ "b/Parte 2 - Funcoes/Exerc\303\255cio 5 e 6 - M\303\241ximo e M\303\255nimo.js" @@ -0,0 +1,21 @@ + +var num1 = prompt("Número 1:"); +var num2 = prompt("Número 2:"); + +//calcula minimo +function calculaMinimo(num1, num2) +{ + if(num1 > num2) { return num2; } + else { return num1; } +} + +//calcula maximo +function calculaMaximo(num1, num2) +{ + if(num1 > num2) { return num1; } + else { return num2; } +} + +//resultado e chamada da funcao +console.log("Menor número: "+ calculaMinimo(num1, num2)); +console.log("Maior número: "+ calculaMaximo(num1, num2)); diff --git "a/Parte 2 - Funcoes/Exerc\303\255cio 7 e 8 - Modulo.js" "b/Parte 2 - Funcoes/Exerc\303\255cio 7 e 8 - Modulo.js" new file mode 100644 index 0000000..fee2cc9 --- /dev/null +++ "b/Parte 2 - Funcoes/Exerc\303\255cio 7 e 8 - Modulo.js" @@ -0,0 +1,16 @@ +var num1 = prompt("Número:"); + +function mod2(number) +{ + if((number) % 2 == 0) + { return true; } + else { return false; } +} + +//resultado e chamada da funcao + +if((mod2(num1))==false) +{ console.log("o numero nao é divisivel por 2"); } + +else if((mod2(num1))== true) +{ console.log("o numero nao é divisivel por 2"); } diff --git "a/Parte 2 - Funcoes/Exerc\303\255cio 9 -Caracteres.js" "b/Parte 2 - Funcoes/Exerc\303\255cio 9 -Caracteres.js" new file mode 100644 index 0000000..8135443 --- /dev/null +++ "b/Parte 2 - Funcoes/Exerc\303\255cio 9 -Caracteres.js" @@ -0,0 +1,20 @@ +var char = prompt("Cactere:"); +var string = prompt("String:"); + +function ContaCactere(string, char) +{ + var aparece = 0; + var tamanhostring = string.length-1 + + for(i = 0; tamanhostring > i; i++) + { + if(char == string[i]) + { + aparece++; + } + } + return aparece; +} + +//resultado e chamada da funcao +console.log(" O caractere " + char + " aparece " + ContaCactere(string,char) + " vezes"); diff --git a/Parte 2 - Funcoes/a b/Parte 2 - Funcoes/a new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Parte 2 - Funcoes/a @@ -0,0 +1 @@ + diff --git "a/Parte 3 - Objetos e Array/Exerc\303\255cio 10 - Range.js" "b/Parte 3 - Objetos e Array/Exerc\303\255cio 10 - Range.js" new file mode 100644 index 0000000..04698f1 --- /dev/null +++ "b/Parte 3 - Objetos e Array/Exerc\303\255cio 10 - Range.js" @@ -0,0 +1,15 @@ +var min = prompt("Digite o mínimo:"); +var max = prompt("Digite o maximo:"); + +function range(min, max) +{ + var intervalo = [max-min]; + var j = 0; + for(i = min; max >= i; i++) + { + intervalo[j]= i; + j++ + } + return intervalo; +} +console.log(range(min,max)); \ No newline at end of file diff --git "a/Parte 3 - Objetos e Array/Exerc\303\255cio 11 - Range + variacao.js" "b/Parte 3 - Objetos e Array/Exerc\303\255cio 11 - Range + variacao.js" new file mode 100644 index 0000000..138aa0e --- /dev/null +++ "b/Parte 3 - Objetos e Array/Exerc\303\255cio 11 - Range + variacao.js" @@ -0,0 +1,18 @@ +var min = prompt("Digite o mínimo:"); +var max = prompt("Digite o maximo:"); +var variacao = prompt("Digite a variação:"); + +function range(min, max, variacao) +{ + var intervalo = []; + var j = 0; + + for(i = min; max >= i; i = (i + variacao)) + { + intervalo[j] = i; + j++; + } + return intervalo; +} + +console.log(range(min,max,variacao)); \ No newline at end of file diff --git "a/Parte 3 - Objetos e Array/Exerc\303\255cio 12 - ReverseArray.js" "b/Parte 3 - Objetos e Array/Exerc\303\255cio 12 - ReverseArray.js" new file mode 100644 index 0000000..692f6ad --- /dev/null +++ "b/Parte 3 - Objetos e Array/Exerc\303\255cio 12 - ReverseArray.js" @@ -0,0 +1,14 @@ +function reverseArray(array) +{ + var reverso = []; + var j = 1; + + for(i = 0; i <= array.length; i++) + { reverso[i] = array[array.length - j]; + j++; + } + + return reverso; +} +var array = [0,1,2,3,4,5,6,7,8,9]; +console.log(reverseArray(array)); \ No newline at end of file diff --git "a/Parte 3 - Objetos e Array/Exerc\303\255cio 13 - Lista.js" "b/Parte 3 - Objetos e Array/Exerc\303\255cio 13 - Lista.js" new file mode 100644 index 0000000..5ffc5ae --- /dev/null +++ "b/Parte 3 - Objetos e Array/Exerc\303\255cio 13 - Lista.js" @@ -0,0 +1,11 @@ +function toList(array) +{ + var list = null; + for (var i = array.length - 1; i >= 0; i--) { + list = { value: array[i], rest: list }; + } + return list; + } + +var array = [0,1,2,3,4,5,6,7,8,9]; +console.log(toList(array)); \ No newline at end of file diff --git "a/Parte 3 - Objetos e Array/Exerc\303\255cio 14 - DeepEquals.js" "b/Parte 3 - Objetos e Array/Exerc\303\255cio 14 - DeepEquals.js" new file mode 100644 index 0000000..26e90f9 --- /dev/null +++ "b/Parte 3 - Objetos e Array/Exerc\303\255cio 14 - DeepEquals.js" @@ -0,0 +1,30 @@ +var objetoTeste = { + idade: 11, + nome: "Joao" +} +var objetoTeste2 = { + idade: 20, + nome: " Joao" +} + +function deepEquals(objteste1, objteste2){ + + var tmp = []; + for (var prop in objteste1) + { tmp.push(prop); } + + var tmp2 = []; + for (var prop in objteste2) + { tmp2.push(prop); } + + if(JSON.stringify(tmp) == JSON.stringify(tmp2)) + { return true; } + else { return false; } +} +//resultado e chamada da funcao + +if(deepEquals(objetoTeste, objetoTeste2) == false) +{ console.log("Os objetos nao sao iguais"); } + +else if(deepEquals(objetoTeste, objetoTeste2) == true) +{ console.log("Os objetos sao iguais"); } \ No newline at end of file diff --git a/Parte 3 - Objetos e Array/a b/Parte 3 - Objetos e Array/a new file mode 100644 index 0000000..7898192 --- /dev/null +++ b/Parte 3 - Objetos e Array/a @@ -0,0 +1 @@ +a diff --git "a/Parte 4 - Funcoes de Alta Ordem/Exec\303\255cio 15 - Ordena\303\247\303\243o.js" "b/Parte 4 - Funcoes de Alta Ordem/Exec\303\255cio 15 - Ordena\303\247\303\243o.js" new file mode 100644 index 0000000..675aa72 --- /dev/null +++ "b/Parte 4 - Funcoes de Alta Ordem/Exec\303\255cio 15 - Ordena\303\247\303\243o.js" @@ -0,0 +1,79 @@ +var array = [1, 2, 3, 4, 5]; + +function bubbleSort(vetor, criterio) +{ + var tamanho = vetor.length; + for (var i = 0; i < tamanho - 1; i++) { + for (var j = 0; j < tamanho - i - 1; j++) { + if (criterio(vetor[j], vetor[j + 1])) { + var temp = vetor[j]; + vetor[j] = vetor[j + 1]; + vetor[j + 1] = temp; + } + } + } + return vetor; +} + +function crescente(a, b) { + return a > b; +} + +function decrescente(a, b) { + return a < b; +} + +function crescenteImpares(a, b) { + if (a % 2 == 0 && b % 2 != 0) { + return false; + } else if (a % 2 != 0 && b % 2 == 0) { + return true; + } else { + return a > b; + } +} + +function decrescenteImpares(a, b) { + if (a % 2 == 0 && b % 2 != 0) { + return true; + } else if (a % 2 != 0 && b % 2 == 0) { + return false; + } else { + return a < b; + } +} + +function crescentePares(vetor) { + var pares = vetor.filter(function(elemento) { + return elemento % 2 == 0; + }); + return bubbleSort(pares, crescente); +} + +function decrescentePares(vetor) { + var pares = vetor.filter(function(elemento) { + return elemento % 2 == 0; + }); + return bubbleSort(pares, decrescente); +} + +var vetor = [10, 4, 8, 2, 6, 7, 3, 1, 5, 9]; +console.log("Vetor: ", vetor); + +var vetorCrescente = bubbleSort(vetor.slice(), crescente); +console.log("Ordenado em ordem crescente: ", vetorCrescente); + +var vetorDecrescente = bubbleSort(vetor.slice(), decrescente); +console.log("Ordenado em ordem decrescente: ", vetorDecrescente); + +var vetorCrescenteImpares = bubbleSort(vetor.slice(), crescenteImpares); +console.log("Ordenado em ordem crescente, com ímpares antes dos pares: ", vetorCrescenteImpares); + +var vetorDecrescenteImpares = bubbleSort(vetor.slice(), decrescenteImpares); +console.log("Ordenado em ordem decrescente, com pares antes dos ímpares: ", vetorDecrescenteImpares); + +var vetorCrescentePares = crescentePares(vetor); +console.log("Ordenado em ordem crescente, apenas os pares: ", vetorCrescentePares); + +var vetorDecrescentePares = decrescentePares(vetor); +console.log("Ordenado em ordem decrescente, apenas os pares: ", vetorDecrescentePares); diff --git "a/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 16 - Criptografia.js" "b/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 16 - Criptografia.js" new file mode 100644 index 0000000..fa63fb6 --- /dev/null +++ "b/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 16 - Criptografia.js" @@ -0,0 +1,24 @@ +function cifraCesar(frase, criterio) +{ + var criptografada = ""; + var tmp = frase.toLowerCase(); + + for(i = 0; i < frase.length; i++) + { + var caractere = tmp.charCodeAt(i); + if (caractere >= 65 && caractere <= 90) + { criptografada += String.fromCharCode((caractere - 65 + criterio) % 26 + 65); } + + else if (caractere >= 97 && caractere <= 122) + { criptografada += String.fromCharCode((caractere - 97 + criterio) % 26 + 97); } + + else { criptografada += tmp.charAt(i); } + } + + return criptografada; +} + +var frase = "Teste para criptografia"; +var criterio = 3; +console.log("Frase: "+ frase); +console.log("Frase Criptografada: " + cifraCesar(frase, criterio)); \ No newline at end of file diff --git "a/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 17 - Verificando Numero.js" "b/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 17 - Verificando Numero.js" new file mode 100644 index 0000000..f0255d7 --- /dev/null +++ "b/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 17 - Verificando Numero.js" @@ -0,0 +1,26 @@ +function verificarNumero(numero, funcaoVerificacao) +{ return funcaoVerificacao(numero); } + + function Impar(numero) + { return numero % 2 !== 0; } + + function Primo(numero) { + if (numero <= 1) { + return false; + } + + for (var i = 2; i <= Math.sqrt(numero); i++) { + if (numero % i === 0) { + return false; + } + } + + return true; + } + + console.log("13=Impar? " + verificarNumero(13, Impar)); // true + console.log("2=Impar? " + verificarNumero(2, Impar)); // false + + console.log("5=Primo? " + verificarNumero(5, Primo)); // true + console.log("6=Primo? " + verificarNumero(6, Primo)); // false + \ No newline at end of file diff --git "a/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 18 - Transformacoes em String.js" "b/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 18 - Transformacoes em String.js" new file mode 100644 index 0000000..6d2bc71 --- /dev/null +++ "b/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 18 - Transformacoes em String.js" @@ -0,0 +1,37 @@ +function transformString(string, Funcao) { + const vowels = ['a', 'e', 'i', 'o', 'u']; + transformedStr = ''; + for (i = 0; i < string.length; i++) { + char = string.charAt(i); + if (vowels.includes(char.toLowerCase())) { + transformedStr += Funcao(char, true); + } else { + transformedStr += Funcao(char, false); + } + } + return transformedStr; + } + + function uppercaseVowelsOrConsonants(char, isVowel) { + if (isVowel) { + return char.toUpperCase(); + } else { + return char.toLowerCase(); + } + } + + function lowercaseVowelsOrConsonants(char, isVowel) { + if (isVowel) { + return char.toLowerCase(); + } else { + return char.toUpperCase(); + } + } + + var string = 'bom dia'; + console.log("String original: " + string); + console.log("Caixa alta nas vogais: " + transformString(string, uppercaseVowelsOrConsonants)); + console.log("Caixa alta nas consoantes: " + transformString(string, (char, isVowel) => isVowel ? char.toLowerCase() : char.toUpperCase())); + console.log("Caixa baixa nas vogais: " + transformString(string, lowercaseVowelsOrConsonants)); + console.log("Caixa baixa nas consoantes: " + transformString(string, (char, isVowel) => isVowel ? char.toUpperCase() : char.toLowerCase())); + \ No newline at end of file diff --git "a/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 19 - Funcoes Matriciais.js" "b/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 19 - Funcoes Matriciais.js" new file mode 100644 index 0000000..91d867a --- /dev/null +++ "b/Parte 4 - Funcoes de Alta Ordem/Exerc\303\255cio 19 - Funcoes Matriciais.js" @@ -0,0 +1,33 @@ +function criarMatriz(linhas, colunas, funcaoescolhida) +{ + var matriz = []; + for (i = 0; i < linhas; i++) { + var linha = []; + for (j = 0; j < colunas; j++) { + linha.push(funcaoescolhida(i, j)); + } + matriz.push(linha); + } + return matriz; + } + +function soma(i, j) +{ return i + j; } + +function produto(i, j) +{ return i * j; } + +function igual(i, j) +{ return i == j ? 1 : 0; } + +function divisao(i, j) +{ return i ** 2 / (j + 1); } + +function maiorOuMenor(i, j) +{ return i > j ? 1 : (i < j ? 5 : 0); } + + console.log(criarMatriz(3, 3, somaIndices)); + console.log(criarMatriz(3, 3, produtoIndices)); + console.log(criarMatriz(3, 3, identidade)); + console.log(criarMatriz(3, 3, divisaoIndices)); + console.log(criarMatriz(3, 3, maiorOuMenor)); \ No newline at end of file diff --git a/Parte 4 - Funcoes de Alta Ordem/a b/Parte 4 - Funcoes de Alta Ordem/a new file mode 100644 index 0000000..7898192 --- /dev/null +++ b/Parte 4 - Funcoes de Alta Ordem/a @@ -0,0 +1 @@ +a