diff --git a/Basico/Diferente.js b/Basico/Diferente.js new file mode 100644 index 0000000..bd0df49 --- /dev/null +++ b/Basico/Diferente.js @@ -0,0 +1,17 @@ +const MAXIMO = 100; + +for(let i = 0; i <= MAXIMO; i++){ + + if ( Number.isInteger( i / 3) && Number.isInteger( i / 5)){ + console.log(i + " FizzBuzz"); + } + else if( Number.isInteger( i / 3)){ + console.log(i + " Fizz"); + } + else if (Number.isInteger( i / 5)){ + console.log(i + " Buzz"); + } + else{ + console.log(i); + } +} \ No newline at end of file diff --git a/Basico/Palindormo.js b/Basico/Palindormo.js new file mode 100644 index 0000000..a4d9454 --- /dev/null +++ b/Basico/Palindormo.js @@ -0,0 +1,33 @@ +let str = prompt("Palavra: "); // string a ser verificada +let tam_str = str.length; //Tamanho da string + +//caracteres +let char_i; +let char_f; + +//O índice do primeiro caractere a ser incluído +let f = tam_str; //indice inicial em ordem decrescente +let i = 0; //indice inicial em ordem crescente + +for(i; i < tam_str; i++){ + //str.substring(x, índice do primeiro caractere a ser excluído) + char_i = str.substring(i, i + 1); //caractere extraído a partir do indice i + char_f = str.substring(f, f - 1); //caractere extraído a partir do indice j + + --f; //diminui o indice da posição dos caracteres + //++i; aumenta o indice da posição dos caracteres + + //caracteres em indices opostos com valores difentes + if(char_i != char_f){ + //Retorna ao usuário e para o for + console.log("Não é um palindromo"); + break; + } + + /*todos os caracteres da string na ordem crescente + e descrescente foram analizados*/ + if(f == 0 && i == tam_str - 1){ + //Retorna ao usuário + console.log("É um palindromo"); + } +} \ No newline at end of file diff --git a/Basico/Triangulo.js b/Basico/Triangulo.js new file mode 100644 index 0000000..e789009 --- /dev/null +++ b/Basico/Triangulo.js @@ -0,0 +1,10 @@ +let char = "# "; //Caracter que se repete +let chars = char; //Soma de Caracteres + +var linhas = prompt("Numero de linhas: "); // Numero de Linhas + +for(let i = 0; i < linhas; i++){ + //Numeros de linhas + 1 = número de caracteres + chars = chars + char; // Soma recursiva + console.log(chars); +} \ No newline at end of file diff --git a/Basico/Xadrez.js b/Basico/Xadrez.js new file mode 100644 index 0000000..45b648c --- /dev/null +++ b/Basico/Xadrez.js @@ -0,0 +1,18 @@ +let char = "# # # #"; //conjunto de caracteres que se repetem +let recuo; //recuo que varia de acordo com a linha + +var linhas = prompt("Numero de linhas: "); // Numero de Linhas + +for(let i = 0; i < linhas; i++){ + + if(i % 2 === 0){ + //Linhas sem recuo são pares ou igual a zero + recuo = ""; + }else{ + //Linhas com recuo são impares + recuo = " "; + } + + let chars = recuo + char; // Soma recuo e conjunto de caracteres + console.log(chars); +} \ No newline at end of file diff --git a/Funcoes.js b/Funcoes.js new file mode 100644 index 0000000..6ff3bd2 --- /dev/null +++ b/Funcoes.js @@ -0,0 +1,53 @@ +//Mínimo e Máximo +function min(a,b) { + if (a < b){ + return a; + } else{ + return b; + } +} + +function max(a,b) { + if (a > b){ + return a; + } else{ + return b; + } +} +//Recursividade +function mod2(number) { + if(Number.isInteger( number / 2)){ + return true; + }else{ + return false; + } +} + +function mod(num, mod) { + if(Number.isInteger( num / mod)){ + return true; + }else{ + return false; + } +} + +//Contando caracteres +function countChars(frase, c){ + let char; + let repete = 0; + if(frase.length > 0){ + for(let i = 0; i < frase.length; i++){ + char = frase.substring(i, i + 1); + if(char === c) { repete++; } + } + } + return repete; +} + +//Implementando funções +console.log( "Menor valor: " + min(3 , 50) ); //Minimo +console.log( "Maior valor: " + max(5 , 30) ); //Maximo +console.log( "333 divisivel por 2 -> " + mod2(333)); //num divisível por 2. +console.log( "456 divisivel por 6 -> " + mod(456, 6) ); //num divisível por mod. +console.log( "Letra a é repetida " + countChars("atividade daw", "a") + " vezes" ); //Contando caracteres + diff --git a/ObjetosArrays.js b/ObjetosArrays.js new file mode 100644 index 0000000..1276063 --- /dev/null +++ b/ObjetosArrays.js @@ -0,0 +1,86 @@ +//Trabalhando com intervalos +function range(min, max, i){ + let dif = Math.abs(max - min) - 1; //diferença - 1 = intervalo entre maximo e minimo + let array = new Array(dif); //vetor temporario + let f = 0; + + for(let j = min + 1; j < max; j++ ){ + array[f] = j; //intervalo no vetor temporario + f++; + } + + let tam_inter=1; //tamanho do intervalo com variacao + f = 0; + for(let k =i; k < dif; k+= i ){ + tam_inter++; //calcula tamanho + } + let intervalo = new Array(tam_inter);// array do intervalo com variacao + if(intervalo.length > 1){ + //tamanho do array de intervalo maior que 1 = possui elementos no intervalo com o critério de variação + for(let k = 0; k < dif; k+= i ){ + intervalo[f] = array[k]; // coloca no intervalo os valores + f++; + } + }else{ + //não possui elementos no intervalo + intervalo[f] = undefined; + } + + return intervalo; +} + + +//Revertendo um array +function reverseArray(array) { + + // indices array em ordem crescente + for (var i = 0; i < array.length; i++) { + // indices array em ordem decrescente + for (var j = 0; j < (array.length - i - 1); j++) { + // array ao reverso. + var temp = array[j] + array[j] = array[j + 1] + array[j + 1] = temp + } + } + return array; +} + + +//Trabalhando com listas +function toList(array) { + + var list = null; + for (let i = array.length-1; i>=0; i--) { + list = {value: array[i], rest: list}; + } + return list; + } + + +//DeepEquals + function deepEquals(obj1, obj2) { + //propriedades dos objetos + var prop1 = Object.getOwnPropertyNames(obj1); + var prop2 = Object.getOwnPropertyNames(obj2); + + /*verifica se propriedades são iguais, + se possuem o mesmo tamanho e valores literais*/ + if(prop1 === prop2 && prop1.length === prop2.length && obj1 === obj2){ + return true; + }else{ + return false; + } +} + +//Implementando funções +let array_1 = ["c" ,"o" ,"c" , "a", "-", "c", "o", "l", "a"] +let array_2 = [1, 2, 3, 4, 5]; +let obj1 = new Object(); +let obj2 = new Object(); + +console.log(range(3, 13, 3)); +console.log(reverseArray(array_1)) +console.log(toList(array_2)) +console.log(deepEquals(obj1, obj2)) +