├── .babelrc ├── .gitignore ├── README.md ├── index.js ├── package-lock.json ├── package.json ├── src ├── bread.js ├── composeAddress.js └── inc2.js ├── tests ├── bread.test.js ├── composeAddress.test.js └── inc2.test.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Javascript TDD Challenges 2 | 3 | Desafios de Javascript usando Ramdascript(as vezes) e TDD em Jest na [live da twitch](https://twitch.tv/anabastosdev) 4 | 5 | **Inc2** 6 | Teste para deixar o ambiente funcionando e explicar currying :) 7 | 8 | **Compose Address** 9 | Desafio de receber uma string com um endereço e transformar em um objeto com os dados. 10 | Feito na [live da twitch](https://twitch.tv/anabastosdev** do dia 29/08/2020. 11 | 12 | **Bread** 13 | Desafio de receber dois sanduiches e falar se o pao e igual ou nao 14 | Feito na live da twitch do dia 26/09/2020. 15 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { add } from 'ramda'; 2 | 3 | console.log(add(1)) 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ramdascript", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "@babel/cli": "^7.10.5", 13 | "@babel/core": "^7.11.4", 14 | "@babel/node": "^7.10.5", 15 | "@babel/preset-env": "^7.11.0", 16 | "babel-jest": "^26.3.0", 17 | "jest": "^26.4.2" 18 | }, 19 | "dependencies": { 20 | "ramda": "^0.27.1" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/bread.js: -------------------------------------------------------------------------------- 1 | import { 2 | lensIndex, 3 | view, 4 | curry, 5 | converge, 6 | equals, 7 | and, 8 | } from 'ramda'; 9 | 10 | const headLens = lensIndex(0); 11 | const lastLens = lensIndex(-1); 12 | 13 | const isSameBread = curry((lenIndex, arr1, arr2) => equals( 14 | view(lenIndex, arr1), 15 | view(lenIndex, arr2) 16 | )); 17 | const isFirstEqual = isSameBread(headLens); 18 | const isLastEqual = isSameBread(lastLens); 19 | 20 | const hasSameBread = converge(and, [isFirstEqual, isLastEqual]); 21 | 22 | export { hasSameBread }; 23 | -------------------------------------------------------------------------------- /src/composeAddress.js: -------------------------------------------------------------------------------- 1 | import { 2 | split, 3 | equals, 4 | type, 5 | findIndex, 6 | splitAt, 7 | pipe, 8 | not, 9 | trim, 10 | evolve, 11 | } from 'ramda'; 12 | 13 | // "Compose Address" 14 | 15 | // Rua Professor Picarolo 162, Apt 62. 16 | // Av. Whatever 1050, bloco B. 17 | // TODO: Considerar tal caso: 5 Travessa Santa Quiteria 18 | // TODO: considerar enderecos de brasilia 19 | 20 | const isNumber = pipe( 21 | parseInt, 22 | isNaN, 23 | not, 24 | ); 25 | 26 | const indexOfFirstNumber = str => findIndex(isNumber, [...str]); 27 | 28 | const transformations = { 29 | name: trim, 30 | number: parseInt, 31 | complement: trim, 32 | }; 33 | 34 | const composeAddress = (input) => { 35 | const [firstLine, complement] = split(',', input); 36 | const [name, number] = splitAt(indexOfFirstNumber(firstLine), firstLine); 37 | return evolve(transformations, { 38 | name, 39 | number, 40 | complement, 41 | }); 42 | }; 43 | 44 | export { isNumber, indexOfFirstNumber, composeAddress }; 45 | -------------------------------------------------------------------------------- /src/inc2.js: -------------------------------------------------------------------------------- 1 | import { add } from 'ramda'; 2 | 3 | const inc2 = add(2); 4 | const inc22 = (x) => x + 2; 5 | 6 | console.log(add(1)); 7 | export default inc2; 8 | -------------------------------------------------------------------------------- /tests/bread.test.js: -------------------------------------------------------------------------------- 1 | import { hasSameBread } from '../src/bread'; 2 | 3 | test('if has same bread returns true', () => { 4 | expect(hasSameBread( 5 | ["pao branco", "alface", "tomate", "pao branco"], 6 | ["pao branco", "alface", "chedder", "pao branco"] 7 | )).toBeTruthy(); 8 | }); 9 | 10 | test('if has different bread returns false', () => { 11 | expect(hasSameBread( 12 | ["pao branco", "alface", "tomate", "pao branco"], 13 | ["pao integral", "alface", "chedder", "pao integral"] 14 | )).toBeFalsy(); 15 | }); 16 | 17 | test('if has different last bread returns false', () => { 18 | expect(hasSameBread( 19 | ["pao branco", "alface", "tomate", "pickles", "pao branco"], 20 | ["pao integral", "chedder", "pao parmesao"] 21 | )).toBeFalsy(); 22 | }); 23 | 24 | test('if has different first bread returns false', () => { 25 | expect(hasSameBread( 26 | ["pao branco", "alface", "pao branco"], 27 | ["pao 9 graos", "alface", "chedder", "pao parmesao"] 28 | )).toBeFalsy(); 29 | }); 30 | -------------------------------------------------------------------------------- /tests/composeAddress.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | composeAddress, 3 | isNumber, 4 | indexOfFirstNumber, 5 | isNumberR, 6 | } from '../src/composeAddress'; 7 | 8 | test('isNumber checks if is a number', () => { 9 | expect(isNumber(1)).toBe(true); 10 | expect(isNumber('a')).toBe(false); 11 | }); 12 | 13 | test('indexOffFirstNumber gets index of first number in array', () => { 14 | expect(indexOfFirstNumber('aus id sdjf110239')).toBe(11); 15 | expect(indexOfFirstNumber('1')).toBe(0); 16 | expect(indexOfFirstNumber(' jsidfj iasjd ')).toBe(-1); 17 | }); 18 | 19 | test('Inputs Rua Professor Picarolo 162, Apt 62 and returns composed address', () => { 20 | expect(composeAddress('Rua Professor Picarolo 162, Apt 62')).toEqual({ 21 | name: 'Rua Professor Picarolo', 22 | number: 162, 23 | complement: 'Apt 62' 24 | }); 25 | 26 | expect(composeAddress('Rua Professor Picarolo 162, Apt 62')).toEqual({ 27 | name: 'Rua Professor Picarolo', 28 | number: 162, 29 | complement: 'Apt 62' 30 | }); 31 | 32 | expect(composeAddress('Av. Whatever 1050, bloco B')).toEqual({ 33 | name: 'Av. Whatever', 34 | number: 1050, 35 | complement: 'bloco B' 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /tests/inc2.test.js: -------------------------------------------------------------------------------- 1 | import inc2 from '../src/inc2'; 2 | 3 | test('adds 2', () => { 4 | expect(inc2(1)).toBe(3); 5 | expect(inc2(0)).toBe(2); 6 | 7 | }); 8 | --------------------------------------------------------------------------------