diff --git a/logic-exercises/anagrama/.gitignore b/logic-exercises/anagrama/.gitignore new file mode 100644 index 0000000..8fe45fe --- /dev/null +++ b/logic-exercises/anagrama/.gitignore @@ -0,0 +1,3 @@ +node_module +build +package-lock.json \ No newline at end of file diff --git a/logic-exercises/anagrama/jest.config.js b/logic-exercises/anagrama/jest.config.js new file mode 100644 index 0000000..97c01ce --- /dev/null +++ b/logic-exercises/anagrama/jest.config.js @@ -0,0 +1,8 @@ +module.exports = { + roots: ["/tests"], + transform: { + "^.+\\.tsx?$": "ts-jest", + }, + testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", + moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], + }; diff --git a/logic-exercises/anagrama/package.json b/logic-exercises/anagrama/package.json new file mode 100644 index 0000000..bc85f61 --- /dev/null +++ b/logic-exercises/anagrama/package.json @@ -0,0 +1,24 @@ +{ + "name": "anagrama", + "version": "1.0.0", + "description": "", + "main": "index.js", + "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", + "dependencies": { + "jest": "^27.5.1", + "ts-jest": "^27.1.3", + "ts-node-dev": "^1.1.8" + }, + "devDependencies": { + "@types/jest": "^27.4.0", + "@types/node": "^17.0.16", + "typescript": "^4.5.5" + } +} diff --git a/logic-exercises/anagrama/src/index.ts b/logic-exercises/anagrama/src/index.ts new file mode 100644 index 0000000..4b7cad3 --- /dev/null +++ b/logic-exercises/anagrama/src/index.ts @@ -0,0 +1,5 @@ +export const palavra2EhAnagramaDe1 =(palavra1: string, palavra2: string) => { + return palavra1.split("").sort().join("") === palavra2.split("").sort().join("") +} + +console.log(palavra2EhAnagramaDe1("anagrama", "nagarama")) \ No newline at end of file diff --git a/logic-exercises/anagrama/tests/index.test.ts b/logic-exercises/anagrama/tests/index.test.ts new file mode 100644 index 0000000..afa002a --- /dev/null +++ b/logic-exercises/anagrama/tests/index.test.ts @@ -0,0 +1,31 @@ +import { palavra2EhAnagramaDe1 } from "../src"; + +test("Palavra2 é um anagrama da Palavra1", ()=>{ + + const palavra1 = "anagrama" + const palavra2 = "nagarama" + + const result =palavra2EhAnagramaDe1(palavra1,palavra2) + + expect(result).toBe(true); +}) + +test("Palavra2 é um anagrama da Palavra1", ()=>{ + + const palavra1 = "gato" + const palavra2 = "toga" + + const result =palavra2EhAnagramaDe1(palavra1,palavra2) + + expect(result).toBe(true); +}) + +test("Palavra2 é um anagrama da Palavra1", ()=>{ + + const palavra1 = "gato" + const palavra2 = "rato" + + const result =palavra2EhAnagramaDe1(palavra1,palavra2) + + expect(result).toBe(false); +}) diff --git a/logic-exercises/anagrama/tsconfig.json b/logic-exercises/anagrama/tsconfig.json new file mode 100644 index 0000000..9e0437d --- /dev/null +++ b/logic-exercises/anagrama/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es6" , + "module": "commonjs", + "outDir": "./build" , + "rootDir": "./" , + "strict": true , + "sourceMap": true, + "removeComments": true, + "esModuleInterop": true , + "forceConsistentCasingInFileNames": true + } + }