From aed6c5990fdc883ee76a90567b7effe0363b8cf6 Mon Sep 17 00:00:00 2001 From: smolinskiJP <104567183+smolinskiJP@users.noreply.github.com> Date: Fri, 14 Apr 2023 10:36:43 -0300 Subject: [PATCH 1/9] Add files via upload --- chess.js | 24 ++++++++++++++++++++++++ piramid.js | 9 +++++++++ 2 files changed, 33 insertions(+) create mode 100644 chess.js create mode 100644 piramid.js diff --git a/chess.js b/chess.js new file mode 100644 index 0000000..659c47c --- /dev/null +++ b/chess.js @@ -0,0 +1,24 @@ +let numLinhas = parseInt(prompt("Quantas linhas?")); + +for(let i = 0; i < numLinhas; i++){ + let line=""; + if(i % 2 == 0){ + for(let j = 0; j < numLinhas; j++){ + if(j % 2 == 0){ + line+= "#"; + } else { + line+= " "; + } + } + } else { + for(let j = 0; j < numLinhas; j++){ + if(j % 2 == 0){ + line+= " "; + } else { + line+= "#"; + } + } + } + console.log(line); + +} \ No newline at end of file diff --git a/piramid.js b/piramid.js new file mode 100644 index 0000000..9631c69 --- /dev/null +++ b/piramid.js @@ -0,0 +1,9 @@ +let numLinhas = parseInt(prompt("Quantas linhas?")); + +for(let i = 0; i < numLinhas; i++){ + let line = "#"; + for(let j = 0; j<=i; j++){ + line+="#"; + } + console.log(line); +} \ No newline at end of file From e1a202344823276ee92ef74841a66a77c6f320fc Mon Sep 17 00:00:00 2001 From: smolinskiJP <104567183+smolinskiJP@users.noreply.github.com> Date: Wed, 19 Apr 2023 14:33:49 -0300 Subject: [PATCH 2/9] Add files via upload --- countChar.js | 8 ++++++++ deepEquals.js | 41 +++++++++++++++++++++++++++++++++++++++++ div35.js | 17 +++++++++++++++++ linkedList.js | 30 ++++++++++++++++++++++++++++++ minmax.js | 14 ++++++++++++++ mod.js | 22 ++++++++++++++++++++++ palindrome.js | 9 +++++++++ range.js | 14 ++++++++++++++ reverseArray.js | 10 ++++++++++ 9 files changed, 165 insertions(+) create mode 100644 countChar.js create mode 100644 deepEquals.js create mode 100644 div35.js create mode 100644 linkedList.js create mode 100644 minmax.js create mode 100644 mod.js create mode 100644 palindrome.js create mode 100644 range.js create mode 100644 reverseArray.js diff --git a/countChar.js b/countChar.js new file mode 100644 index 0000000..c3c342c --- /dev/null +++ b/countChar.js @@ -0,0 +1,8 @@ +function countChars(frase, c){ + return frase.split(c).length - 1; +} + +let frase = prompt("Qual palavra?"); +let c = prompt("Char?"); + +console.log(countChars(frase, c)); \ No newline at end of file diff --git a/deepEquals.js b/deepEquals.js new file mode 100644 index 0000000..c663cfb --- /dev/null +++ b/deepEquals.js @@ -0,0 +1,41 @@ +function deepEquals(obj1, obj2){ + let objK1 = Object.keys(obj1); + let objK2 = Object.keys(obj2); + + if (objK1.length !== objK2.length) return false; + + for(let key of objK1){ + let v1 = obj1[key]; + let v2 = obj2[key]; + + let isObj = isObject(v1) && isObject(v2); + if((isObj && !deepEquals(v1, v2)) || (!isObj && (v1 !== v2))) return false; + } + + return true; +} + +function isObject(obj){ + return obj!=null && typeof obj === "object"; +} + +const obj1 = { + "nome" : "smola", + "matricula" : "2021951450", + "idade" : "17", +}; + +const obj2 = { + "nome" : "leo", + "matricula" : "2021951566", + "idade" : "17", +}; + +const obj3 = { + "nome" : "smola", + "matricula" : "2021951450", + "idade" : "17", +}; + +console.log(deepEquals(obj1, obj3)); +console.log(deepEquals(obj1, obj2)); \ No newline at end of file diff --git a/div35.js b/div35.js new file mode 100644 index 0000000..227eac2 --- /dev/null +++ b/div35.js @@ -0,0 +1,17 @@ +for(let i = 0; i < 100; i++){ + let line = ''; + + if (i % 3 == 0){ + line+= "Fizz"; + } + if (i % 5 == 0){ + line+= "Buzz"; + } + + if (line === ''){ + console.log(i); + } else{ + console.log(line); + } + +} \ No newline at end of file diff --git a/linkedList.js b/linkedList.js new file mode 100644 index 0000000..8874a2c --- /dev/null +++ b/linkedList.js @@ -0,0 +1,30 @@ +class List { + constructor(value, rest){ + this.value = value; + this.rest = rest; + } + + print(){ + let line = this.value ; + let p = this.rest; + while(p){ + line += ", " + p.value; + p = p.rest; + } + console.log(line); + } +} + +function toList(array){ + rest = null; + for(let i = 0; i < array.length; i++){ + var list = new List(array[i], rest); + rest = list; + } + return list; +} + +let array = [1, 2, 3, 4, 5]; +let list = toList(array); + +list.print(); \ No newline at end of file diff --git a/minmax.js b/minmax.js new file mode 100644 index 0000000..5cc5193 --- /dev/null +++ b/minmax.js @@ -0,0 +1,14 @@ +function minMax(a, b){ + if (a < b){ + return a; + } else if(b < a){ + return b; + } else { + return "Igual"; + } +} + +let a = parseInt(prompt("a?")); +let b = parseInt(prompt("b?")); + +console.log(minMax(a, b)); \ No newline at end of file diff --git a/mod.js b/mod.js new file mode 100644 index 0000000..1ca5f7e --- /dev/null +++ b/mod.js @@ -0,0 +1,22 @@ +function mod2(number){ + return (number%2==0); +} + +function mod(num, modu){ + if(num >= modu){ + return mod((num-modu), modu); + } else if(num == 0){ + return true; + } else { + return false; + } +} + +let num = parseInt(prompt("num")); +let modu = parseInt(prompt("mod")); + +if (mod(num,modu)){ + console.log("É divisível"); +} else { + console.log("Não é divisível"); +} \ No newline at end of file diff --git a/palindrome.js b/palindrome.js new file mode 100644 index 0000000..68845a6 --- /dev/null +++ b/palindrome.js @@ -0,0 +1,9 @@ +let word = prompt("Qual palavra?"); + +word = word.toLowerCase(); +let drow = word.split('').reverse().join(''); +if (drow === word){ + console.log("Palíndromo"); +} else { + console.log("Não palíndromo"); +} \ No newline at end of file diff --git a/range.js b/range.js new file mode 100644 index 0000000..4245323 --- /dev/null +++ b/range.js @@ -0,0 +1,14 @@ +function range(min, max, i){ + let array = []; + for(let j = min; j <=max; j+=i){ + array.push(j); + } + return array; +} + + +let min = parseInt(prompt("min")); +let max = parseInt(prompt("max")); +let i = parseInt(prompt("i")); + +console.log(range(min,max,i)); \ No newline at end of file diff --git a/reverseArray.js b/reverseArray.js new file mode 100644 index 0000000..71e1a82 --- /dev/null +++ b/reverseArray.js @@ -0,0 +1,10 @@ +function reverseArray(array){ + let reversed = []; + for(let i = 0; i < array.length; i++){ + reversed.push(parseInt(array[array.length - (i + 1)])); + } + return reversed; +} + +let array = [1, 2, 3, 4, 5]; +console.log(reverseArray(array)); \ No newline at end of file From 1780a674243bc2c28946add15f77085127d270f0 Mon Sep 17 00:00:00 2001 From: smolinskiJP <104567183+smolinskiJP@users.noreply.github.com> Date: Wed, 19 Apr 2023 14:57:54 -0300 Subject: [PATCH 3/9] Update mod.js --- mod.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mod.js b/mod.js index 1ca5f7e..e93aca9 100644 --- a/mod.js +++ b/mod.js @@ -1,5 +1,11 @@ function mod2(number){ - return (number%2==0); + if(number >= 2){ + return mod2((number-2)); + } else if(number == 0){ + return true; + } else { + return false; + } } function mod(num, modu){ @@ -19,4 +25,4 @@ if (mod(num,modu)){ console.log("É divisível"); } else { console.log("Não é divisível"); -} \ No newline at end of file +} From 3b631b783793fa6ffcad1c1cbf5f65be08ee5b07 Mon Sep 17 00:00:00 2001 From: smolinskiJP <104567183+smolinskiJP@users.noreply.github.com> Date: Fri, 21 Apr 2023 23:14:06 -0300 Subject: [PATCH 4/9] Create bubbleSort.js --- bubbleSort.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 bubbleSort.js diff --git a/bubbleSort.js b/bubbleSort.js new file mode 100644 index 0000000..e8ca6a2 --- /dev/null +++ b/bubbleSort.js @@ -0,0 +1,45 @@ +const array = [7, 2, 4, 1, 6, 1, 5, 8]; + +function bubbleSort(array, func){ + for(let i = 0; i < array.length-1; i++){ + for(let j = 0; j < array.length-1; j++){ + if(func(array[j], array[j+1]) > 0){ + [array[j], array[j+1]] = [array[j+1], array[j]]; + } + } + } + return array; +} + +function crescente(a, b){ + return a - b; +} + +function decrescente(a, b){ + return b - a; +} + +function crescImpar(a, b){ + if((a % 2 === 1) && (b % 2 === 0)){ + return -1; + } else if((a % 2 === 0) && (b % 2 === 1)){ + return 1; + } else { + return a - b; + } +} + +function decrescPar(a, b){ + if ((a % 2 === 0) && (b % 2 === 1)) { + return -1; + } else if ((a % 2 === 1) && (b % 2 === 0)) { + return 1; + } else { + return b - a; + } +} + +console.log(bubbleSort(array, crescente)); +console.log(bubbleSort(array, decrescente)); +console.log(bubbleSort(array, crescImpar)); +console.log(bubbleSort(array, decrescPar)); From 86e8e5a6d11f22ed56af567b97d8f2d821aa235a Mon Sep 17 00:00:00 2001 From: smolinskiJP <104567183+smolinskiJP@users.noreply.github.com> Date: Fri, 21 Apr 2023 23:25:06 -0300 Subject: [PATCH 5/9] Create cifraCesar.js --- cifraCesar.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cifraCesar.js diff --git a/cifraCesar.js b/cifraCesar.js new file mode 100644 index 0000000..e5113b9 --- /dev/null +++ b/cifraCesar.js @@ -0,0 +1,25 @@ +const alfabeto = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; +function cifraCesar(string, skip){ + let cifra = ''; + let achou = false; + string = string.toLowerCase(); + + for(let i = 0; i < string.length; i++){ + for(let j = 0; j < alfabeto.length; j++){ + if(string[i] == alfabeto[j]){ + cifra += alfabeto[(j + skip) % 26]; + achou = true; + } + } + if(achou == 0){ + cifra += string[i]; + } + achou = 0; + } + return cifra; +} + +const string = "Hello World!"; +console.log(cifraCesar(string, 1)); +console.log(cifraCesar(string, 0)); +console.log(cifraCesar(string, 5)); From 35f929e7f29f0fc9feb7279563878330c5c376df Mon Sep 17 00:00:00 2001 From: smolinskiJP <104567183+smolinskiJP@users.noreply.github.com> Date: Fri, 21 Apr 2023 23:31:22 -0300 Subject: [PATCH 6/9] Create numCheck.js --- numCheck.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 numCheck.js diff --git a/numCheck.js b/numCheck.js new file mode 100644 index 0000000..fc1f3e1 --- /dev/null +++ b/numCheck.js @@ -0,0 +1,20 @@ +function numCheck(num, func){ + return func(num); +} + +function ehImpar(num){ + return num % 2 === 1; +} + +function ehPrimo(num){ + if (num <= 1) return false; + for(let i = 2; i < num/2; i++){ + if(num % i === 0) return false; + } + return true; +} + +console.log(numCheck(3, ehImpar)); +console.log(numCheck(2, ehImpar)); +console.log(numCheck(3, ehPrimo)); +console.log(numCheck(2, ehPrimo)); From 858552fb2f11f49d18ad124e94f3ec7d54387b4a Mon Sep 17 00:00:00 2001 From: smolinskiJP <104567183+smolinskiJP@users.noreply.github.com> Date: Fri, 21 Apr 2023 23:41:02 -0300 Subject: [PATCH 7/9] Create stringTransform.js --- stringTransform.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 stringTransform.js diff --git a/stringTransform.js b/stringTransform.js new file mode 100644 index 0000000..93addb2 --- /dev/null +++ b/stringTransform.js @@ -0,0 +1,34 @@ +function stringTransform(string, func){ + let transform = ''; + for(let i = 0; i < string.length; i++){ + transform += func(string[i]); + } + return transform; +} + +function vogalMaiusc(char){ + if(/[aeiou]/i.test(char)) return char.toUpperCase(); + else return char; +} + +function consoanteMaiusc(char){ + if(/[bcdfghjklmnpqrstvwxyz]/i.test(char)) return char.toUpperCase(); + else return char; +} + +function vogalMinusc(char){ + if(/[aeiou]/i.test(char)) return char.toLowerCase(); + else return char; +} + +function consoanteMinusc(char){ + if(/[bcdfghjklmnpqrstvwxyz]/i.test(char)) return char.toLowerCase(); + else return char; +} + +let string = "Hello Earth!"; + +console.log(stringTransform(string, vogalMaiusc)); +console.log(stringTransform(string, consoanteMaiusc)); +console.log(stringTransform(string, vogalMinusc)); +console.log(stringTransform(string, consoanteMinusc)); From 593114b0deea60c5e1dd6356ad8e35f7ba74ea23 Mon Sep 17 00:00:00 2001 From: smolinskiJP <104567183+smolinskiJP@users.noreply.github.com> Date: Fri, 21 Apr 2023 23:50:11 -0300 Subject: [PATCH 8/9] Create matriz.js --- matriz.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 matriz.js diff --git a/matriz.js b/matriz.js new file mode 100644 index 0000000..df2df82 --- /dev/null +++ b/matriz.js @@ -0,0 +1,40 @@ +function criaMatriz(tam, func){ + let matriz = []; + for(let i = 1; i <= tam; i++){ + let linha = []; + for(let j = 1; j <= tam; j++){ + linha.push(func(i, j)); + } + matriz.push(linha); + } + return matriz; +} + +function func1(i, j){ + return i + j +} + +function func2(i, j){ + return i * j; +} + +function func3(i, j){ + if (i == j) return 1; + else return 0; +} + +function func4(i, j){ + return (i*i)/(j+1); +} + +function func5(i, j){ + if(i > j) return 1; + else if (i < j) return 5; + else return 0; +} + +console.log(criaMatriz(5, func1)); +console.log(criaMatriz(5, func2)); +console.log(criaMatriz(5, func3)); +console.log(criaMatriz(5, func4)); +console.log(criaMatriz(5, func5)); From 95fb1d9e8617e681c5bbd8c0ae3a447a8962be81 Mon Sep 17 00:00:00 2001 From: smolinskiJP <104567183+smolinskiJP@users.noreply.github.com> Date: Tue, 25 Apr 2023 11:35:42 -0300 Subject: [PATCH 9/9] Update minmax.js --- minmax.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/minmax.js b/minmax.js index 5cc5193..3c7e94a 100644 --- a/minmax.js +++ b/minmax.js @@ -1,4 +1,4 @@ -function minMax(a, b){ +function min(a, b){ if (a < b){ return a; } else if(b < a){ @@ -8,7 +8,18 @@ function minMax(a, b){ } } +function max(a, b){ + if(a>b){ + return a; + } else if(b>a){ + return b; + } else{ + return "Igual"; + } +} + let a = parseInt(prompt("a?")); let b = parseInt(prompt("b?")); -console.log(minMax(a, b)); \ No newline at end of file +console.log(min(a, b)); +console.log(max(a, b));