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

Resoluçao dos exercicios da aula 72 #62

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
2 changes: 2 additions & 0 deletions semana23/exercicios-aula72/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/build
54 changes: 54 additions & 0 deletions semana23/exercicios-aula72/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
### Exercícios aula 72

## 1.
### Resposta:
~~~typescript
function isOneEdit(target: string, reference: string){
if(reference.length > target.length + 1 || reference.length <= target.length -2){
return false
}

const targetCharList = target.split("")
const referenceCharList = reference.split("")

const strangerCharList = referenceCharList.filter(char=>{
return ! targetCharList.includes(char)
})

if(strangerCharList.length > 1){
return false
}

return true
}
~~~

## 2.
### Resposta:
~~~typescript
interface HashTable{
[key: string]: number
}

function sequenceCount(target: string){
const count: HashTable = {}
const splitedStr = target.split("")
let finalStr = ""

splitedStr.forEach(char=>{
if(count[char]){
count[char] += 1
}else{
count[char] = 1
}
})

for(const char in count){
finalStr += char+`${count[char]}`
}

return finalStr.length > target.length ? target : finalStr
}
~~~

### Fim dos exercícios
69 changes: 69 additions & 0 deletions semana23/exercicios-aula72/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions semana23/exercicios-aula72/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "exercicios-aula72",
"version": "1.0.0",
"description": "Exercicios aula 72, da semana 23",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "clear && tsc && ts-node ./src/index.ts"
},
"author": "OsmanRodrigues",
"license": "ISC",
"dependencies": {
"@types/node": "^14.6.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.2"
}
}
43 changes: 43 additions & 0 deletions semana23/exercicios-aula72/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function isOneEdit(target: string, reference: string){
if(reference.length > target.length + 1 || reference.length <= target.length -2){
return false
}

const targetCharList = target.split("")
const referenceCharList = reference.split("")

const strangerCharList = referenceCharList.filter(char=>{
return ! targetCharList.includes(char)
})

if(strangerCharList.length > 1){
return false
}

return true
}

interface HashTable{
[key: string]: number
}

function sequenceCount(target: string){
const count: HashTable = {}
const splitedStr = target.split("")
let finalStr = ""

splitedStr.forEach(char=>{
if(count[char]){
count[char] += 1
}else{
count[char] = 1
}
})

for(const char in count){
finalStr += char+`${count[char]}`
}

return finalStr.length > target.length ? target : finalStr
}

14 changes: 14 additions & 0 deletions semana23/exercicios-aula72/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"outDir": "build",
"sourceMap": true,
"target": "es6",
"module": "commonjs",
"esModuleInterop": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}