-
Notifications
You must be signed in to change notification settings - Fork 117
João Smolinski JavaScript #70
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
smolinskiJP
wants to merge
9
commits into
COLTEC-DAW:master
Choose a base branch
from
smolinskiJP:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aed6c59
Add files via upload
smolinskiJP e1a2023
Add files via upload
smolinskiJP 1780a67
Update mod.js
smolinskiJP 3b631b7
Create bubbleSort.js
smolinskiJP 86e8e5a
Create cifraCesar.js
smolinskiJP 35f929e
Create numCheck.js
smolinskiJP 858552f
Create stringTransform.js
smolinskiJP 593114b
Create matriz.js
smolinskiJP 95fb1d9
Update minmax.js
smolinskiJP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| function min(a, b){ | ||
| if (a < b){ | ||
| return a; | ||
| } else if(b < a){ | ||
| return b; | ||
| } else { | ||
| return "Igual"; | ||
| } | ||
| } | ||
|
|
||
| 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(min(a, b)); | ||
| console.log(max(a, b)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| function mod2(number){ | ||
| if(number >= 2){ | ||
| return mod2((number-2)); | ||
| } else if(number == 0){ | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| 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"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Faltou método genérico de criptografia