Skip to content
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

exercicio logica #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions modulo6/exercicios-logica/checa-parenteses/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "checa-parenteses",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsc && node ./build/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
64 changes: 64 additions & 0 deletions modulo6/exercicios-logica/checa-parenteses/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
function checaParenteses(str: string) {
let output = true
const parenteses = []
for (let char of str) {
if (char === '(' || char === '[' || char === '{') {
parenteses.push(char)
}
if (char === ')' || char === ']' || char === '}') {
let parenteseFechado = false
for (let i = parenteses.length - 1; i >= 0; i--) {
switch (char) {
case ')':
if (parenteses[i] === '(') {
parenteseFechado = true
parenteses.splice(i, 1)
i = -1
}
if (parenteses[i] === '[' || parenteses[i] === '{') {
output = false
i = -1
}
break
case ']':
if (parenteses[i] === '[') {
parenteseFechado = true
parenteses.splice(i, 1)
i = -1
}
if (parenteses[i] === '(' || parenteses[i] === '{') {
output = false
i = -1
}
break
case '}':
if (parenteses[i] === '{') {
parenteseFechado = true
parenteses.splice(i, 1)
i = -1
}
if (parenteses[i] === '[' || parenteses[i] === '(') {
output = false
i = -1
}
break

}

}
if (!parenteseFechado) {
output = false
}
}
}
if (parenteses.length) {
output = false
}
return output
}

console.log(checaParenteses("()"));
console.log(checaParenteses("()[]{}"));
console.log(checaParenteses("(]"));
console.log(checaParenteses("([)]"));
console.log(checaParenteses("{[]}"));
13 changes: 13 additions & 0 deletions modulo6/exercicios-logica/checa-parenteses/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version */
"module": "commonjs", /* Specify module code generation */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "./build", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. */
"removeComments": true, /* Do not emit comments to output. */
"noImplicitAny": true, /* Raise error on declarations with an implied 'any' type. */
"esModuleInterop": true, /*Pra quando da problema importando cors, express no topo do arquivo*/
"resolveJsonModule": true
}
}