Skip to content
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 logic-exercises/prefixoComum/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
8 changes: 8 additions & 0 deletions logic-exercises/prefixoComum/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
roots: ["<rootDir>/tests"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};
2,936 changes: 2,936 additions & 0 deletions logic-exercises/prefixoComum/package-lock.json

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions logic-exercises/prefixoComum/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "prefixoComum",
"version": "1.0.0",
"description": "",
"main": "jest.config.js",
"directories": {
"test": "tests"
},
"dependencies": {
"jest": "^27.4.7",
"ts-jest": "^27.1.3",
"ts-node-dev": "^1.1.8"
},
"devDependencies": {
"@types/jest": "^27.4.0",
"@types/node": "^17.0.14",
"typescript": "^4.5.5"
},
"scripts": {
"dev": "ts-node-dev --transpile-only --ignore-watch node_modules ./src/index.ts",
"test": "clear && jest",
"start": "tsc && node ./build/src/index.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}
22 changes: 22 additions & 0 deletions logic-exercises/prefixoComum/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const prefixoComun = (palavras:string[]) => {
if(palavras.length === 0) return ""

let commonPrefix = ""
for(let i = 0; i < palavras[0].length; i++) {
let currentChar = palavras[0][i]


for(let j = 0; j < palavras.length; j++) {
if(palavras[j][i] !== currentChar) {
return commonPrefix
}
}

if(currentChar) {
commonPrefix += currentChar
}
}

return commonPrefix
};

31 changes: 31 additions & 0 deletions logic-exercises/prefixoComum/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { prefixoComun } from "../src";

test("prefixoComun", ()=>{

const array = ["flower","flow","flight"]

const result = prefixoComun(array)

expect(result).toBe("fl");

})

test("prefixoComun", ()=>{

const array =["dog","racecar","car"]

const result = prefixoComun(array)

expect(result).toBe("");

})

test("prefixoComun", ()=>{

const array =["coracao","cor","corona","coreia"]

const result = prefixoComun(array)

expect(result).toBe("cor");

})
13 changes: 13 additions & 0 deletions logic-exercises/prefixoComum/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es6" ,
"module": "commonjs",
"outDir": "./build" ,
"rootDir": "./" ,
"strict": true ,
"sourceMap": true,
"removeComments": true,
"esModuleInterop": true ,
"forceConsistentCasingInFileNames": true
}
}
Loading