From b45497bcfae95a3c7d185d5e830e4b14ab049a74 Mon Sep 17 00:00:00 2001 From: arturgonzaga320 Date: Thu, 20 Apr 2023 19:26:45 -0300 Subject: [PATCH 1/4] Conceitos basicos --- conceitos_basicos/contador.js | 7 +++++++ conceitos_basicos/palindromo.js | 19 +++++++++++++++++++ conceitos_basicos/triangulo.js | 6 ++++++ conceitos_basicos/xadez.js | 8 ++++++++ 4 files changed, 40 insertions(+) create mode 100644 conceitos_basicos/contador.js create mode 100644 conceitos_basicos/palindromo.js create mode 100644 conceitos_basicos/triangulo.js create mode 100644 conceitos_basicos/xadez.js diff --git a/conceitos_basicos/contador.js b/conceitos_basicos/contador.js new file mode 100644 index 0000000..b1abd84 --- /dev/null +++ b/conceitos_basicos/contador.js @@ -0,0 +1,7 @@ +for (i = 1; i< 100; i++) +{ + if (i/3 == parseInt(i/3) && i/5 == parseInt(i/5)) console.log("FizzBuzz"); + else if (i/3 == parseInt(i/3)) console.log("Fizz"); + else if (i/5 == parseInt(i/5)) console.log("Buzz"); + else console.log(i); +} \ No newline at end of file diff --git a/conceitos_basicos/palindromo.js b/conceitos_basicos/palindromo.js new file mode 100644 index 0000000..74da549 --- /dev/null +++ b/conceitos_basicos/palindromo.js @@ -0,0 +1,19 @@ +let str = "arara"; + +// cria vetor a partir da string dada pelo usuario -> split +let rev = str.split(""); +// inverte a ordem dos elementos do vetor-> reverse +rev = rev.reverse(); +// junto elementos do vetor em uma string -> join +rev = rev.join(""); + +for(i=0, test = true; i < str.length;i++) +{ + if (str[i] != rev[i]) + { + test = false; + console.log("\"" + str +"\""+" não é um palíndromo"); + break; + } +} +if (test == true) console.log("\"" + str+"\""+" é um palíndromo"); \ No newline at end of file diff --git a/conceitos_basicos/triangulo.js b/conceitos_basicos/triangulo.js new file mode 100644 index 0000000..84b4ea0 --- /dev/null +++ b/conceitos_basicos/triangulo.js @@ -0,0 +1,6 @@ +var n_linhas = prompt ("Digite a quantidade de linhas"); +for (i = 1; i <=n_linhas; i++) +{ + for( j=0, hash="#" ; j Date: Thu, 20 Apr 2023 19:28:11 -0300 Subject: [PATCH 2/4] Conceitos basicos --- conceitos_basicos/{xadez.js => xadrez.js} | 1 - 1 file changed, 1 deletion(-) rename conceitos_basicos/{xadez.js => xadrez.js} (99%) diff --git a/conceitos_basicos/xadez.js b/conceitos_basicos/xadrez.js similarity index 99% rename from conceitos_basicos/xadez.js rename to conceitos_basicos/xadrez.js index 41ec58a..6bcb775 100644 --- a/conceitos_basicos/xadez.js +++ b/conceitos_basicos/xadrez.js @@ -1,5 +1,4 @@ var n_linhas = prompt ("Digite a quantidade de linhas"); - for (i = 1, alt=true; i <=n_linhas; i++, alt=!alt) { var hash = "# # # # #" From 4368ac1086c115d330183c30ee8bf72b87898ca2 Mon Sep 17 00:00:00 2001 From: arturgonzaga320 Date: Thu, 20 Apr 2023 21:17:08 -0300 Subject: [PATCH 3/4] =?UTF-8?q?Fun=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- funcao/contador_char.js | 13 ++++++++++++ funcao/min_max.js | 45 +++++++++++++++++++++++++++++++++++++++++ funcao/mod.js | 6 ++++++ funcao/mod2.js | 6 ++++++ 4 files changed, 70 insertions(+) create mode 100644 funcao/contador_char.js create mode 100644 funcao/min_max.js create mode 100644 funcao/mod.js create mode 100644 funcao/mod2.js diff --git a/funcao/contador_char.js b/funcao/contador_char.js new file mode 100644 index 0000000..9da1838 --- /dev/null +++ b/funcao/contador_char.js @@ -0,0 +1,13 @@ +function countChars(frase,len ,c) +{ + let n_vezes = 0; + var vet_frase = frase.split(""); + + for(i = 0; i < len; i++) + { + if (vet_frase[i] == c) n_vezes++; + } + return n_vezes; +} +var str = "arrivederci" +console.log(countChars(str,str.length, "r")); \ No newline at end of file diff --git a/funcao/min_max.js b/funcao/min_max.js new file mode 100644 index 0000000..7021a9d --- /dev/null +++ b/funcao/min_max.js @@ -0,0 +1,45 @@ +function min (a, b) +{ + let max; + let min; + let inter = 0; + if ( a > b ) + { + inter = a - b; + max = a; + min = b; + } + else + { + inter = b - a; + max = b; + min = a; + } + + if (inter == 0) return NaN; + return min + 1; +} +function max (a, b) +{ + let max; + let min; + let inter = 0; + if ( a > b ) + { + inter = a - b; + max = a; + min = b; + } + else + { + inter = b - a; + max = b; + min = a; + } + + if (inter == 0) return NaN; + return max - 1; +} +let x = min(2,6); +let y = max(2,6); +console.log("min:", x +"\nmax:", y); \ No newline at end of file diff --git a/funcao/mod.js b/funcao/mod.js new file mode 100644 index 0000000..edf6060 --- /dev/null +++ b/funcao/mod.js @@ -0,0 +1,6 @@ +function mod (num,mod) +{ + if (num/mod == parseInt(num/mod)) return true; + else return false; +} +console.log(mod(8,2)); \ No newline at end of file diff --git a/funcao/mod2.js b/funcao/mod2.js new file mode 100644 index 0000000..97ca556 --- /dev/null +++ b/funcao/mod2.js @@ -0,0 +1,6 @@ +function mod2 (number) +{ + if (number/2 == parseInt(number/2)) return true; + else return false; +} +console.log(mod2(8)); \ No newline at end of file From d40acb713914f332c4a66f466b677755dbfc0d88 Mon Sep 17 00:00:00 2001 From: arturgonzaga320 Date: Fri, 21 Apr 2023 18:12:59 -0300 Subject: [PATCH 4/4] Objetos e Arrays --- objetos_arrays/deep_equal.js | 20 ++++++++++++++++++++ objetos_arrays/intervalos.js | 11 +++++++++++ objetos_arrays/list.js | 32 ++++++++++++++++++++++++++++++++ objetos_arrays/rev_array.js | 6 ++++++ objetos_arrays/variacao.js | 11 +++++++++++ 5 files changed, 80 insertions(+) create mode 100644 objetos_arrays/deep_equal.js create mode 100644 objetos_arrays/intervalos.js create mode 100644 objetos_arrays/list.js create mode 100644 objetos_arrays/rev_array.js create mode 100644 objetos_arrays/variacao.js diff --git a/objetos_arrays/deep_equal.js b/objetos_arrays/deep_equal.js new file mode 100644 index 0000000..d43c87a --- /dev/null +++ b/objetos_arrays/deep_equal.js @@ -0,0 +1,20 @@ +function deepEquals(obj1,obj2) +{ + var keys1 = []; + for(var key1 in obj1) keys1.push(key1); + console.log(keys1) + + var keys2 = []; + for(var key2 in obj2) keys2.push(key2); + console.log(keys2) + + if (JSON.stringify(keys1) === JSON.stringify(keys2)) return true; + else return false; +} + +var a = {"letter":"A","num":42}; +var b = {"letter":"B","num":73}; +var clone = {"letter":"A","num":42}; + +console.log(deepEquals(a,b)); +console.log(deepEquals(a,clone)); \ No newline at end of file diff --git a/objetos_arrays/intervalos.js b/objetos_arrays/intervalos.js new file mode 100644 index 0000000..c1a8eaf --- /dev/null +++ b/objetos_arrays/intervalos.js @@ -0,0 +1,11 @@ +function range(min,max) +{ + let inter= max - min; + const vet = []; + for (i = 1; i < inter; i++) + { + vet.push(min+i); + } + return vet; +} +console.log(range(2,8)); \ No newline at end of file diff --git a/objetos_arrays/list.js b/objetos_arrays/list.js new file mode 100644 index 0000000..627c013 --- /dev/null +++ b/objetos_arrays/list.js @@ -0,0 +1,32 @@ +function toList(array, len) +{ + var list = { + value: 0, + rest: null, + }; + for (i=0;i