From 8d6eeffc79e527eb2f786a76d76711aa32c8ae8c Mon Sep 17 00:00:00 2001 From: Marcos Daniel Romero Garcia Date: Wed, 23 Apr 2025 00:31:24 -0500 Subject: [PATCH 1/2] Prueba tecnica terminada --- .gitignore | 1 + README.md | 66 --------- index.js | 91 ++++++++++++ package-lock.json | 359 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 31 ++++ 5 files changed, 482 insertions(+), 66 deletions(-) create mode 100644 .gitignore create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md index 668a6a2..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,66 +0,0 @@ -# Reto Técnico: Procesamiento de Transacciones Bancarias (CLI) - -## Objetivo: - -Desarrolla una aplicación de línea de comandos (CLI) que procese un archivo CSV con transacciones bancarias y genere un reporte que incluya: - -- **Balance Final:** - Suma de los montos de las transacciones de tipo "Crédito" menos la suma de los montos de las transacciones de tipo "Débito". - -- **Transacción de Mayor Monto:** - Identificar el ID y el monto de la transacción con el valor más alto. - -- **Conteo de Transacciones:** - Número total de transacciones para cada tipo ("Crédito" y "Débito"). - ---- - -## Instrucciones - -1. **Repositorio Base:** - Clona o haz un fork del repositorio base disponible en: - `https://github.com/codeableorg/interbank-academy-25` - -2. **Entrada de Datos:** - La aplicación deberá leer un archivo CSV. Ejemplo de contenido: - - ``` - id,tipo,monto - 1,Crédito,100.00 - 2,Débito,50.00 - 3,Crédito,200.00 - 4,Débito,75.00 - 5,Crédito,150.00 - ``` - -3. **Salida del Programa:** - La aplicación debe mostrar el reporte final en la terminal. - Ejemplo de salida: - - ``` - Reporte de Transacciones - --------------------------------------------- - Balance Final: 325.00 - Transacción de Mayor Monto: ID 3 - 200.00 - Conteo de Transacciones: Crédito: 3 Débito: 2 - ``` - -4. **Lenguaje de Programación:** - Utiliza el lenguaje de tu preferencia. Opciones recomendadas: - - - Python - - Java - - C# - - JavaScript (Node.js) - -5. **README del Proyecto:** - Incluye un archivo `README.md` con la siguiente estructura: - - - **Introducción:** Breve descripción del reto y su propósito. - - **Instrucciones de Ejecución:** Cómo instalar dependencias y ejecutar la aplicación. - - **Enfoque y Solución:** Lógica implementada y decisiones de diseño. - - **Estructura del Proyecto:** Archivos y carpetas principales. - -6. **Documentación y Calidad del Código:** - - Código bien documentado y fácil de leer. - - Comentarios explicando pasos clave y lógica del programa. diff --git a/index.js b/index.js new file mode 100644 index 0000000..ad1faf3 --- /dev/null +++ b/index.js @@ -0,0 +1,91 @@ +// - Balance Final +// - Transacción de Mayor Monto +// - Conteo de Créditos y Débitos + +const fs = require('fs') +const path = require('path'); + +// RUTA DEL CSV +const archivo = process.argv[2] || 'data.csv' +const ruta = path.resolve(process.cwd(), archivo); + +// PASAR CSV A ARRAY +function leerArchivo(rutaArchivo) { + let data; + + try { + data = fs.readFileSync(rutaArchivo, 'utf8'); + } + catch { + console.error(`error: noo se encontro "${rutaArchivo}"`); + process.exit(1) + } + + const [header, ...filas] = data.trim().split('\n'); // 18,Débito,385.45 + const columnas = header.split(',').map(c => c.trim()); // id,tipo,monto + + return filas.map(line => { // 18,Debito,385.45 + const valores = line.split(',').map(v => v.trim()); // [ "18", "Debito", "385.45" ] + const obj = {}; + + columnas.forEach ((col, i) => { // id:0,tipo:1,monto:2 + obj[col] = valores[i] // id : 18 , tipo: debito , monto : 385.45 + }); + + return { + id: Number(obj.id), // 18 + tipo: obj.tipo, // debito + monto: Number(obj.monto) // 385.45 + }; + }); + +} + +function procesarLogica(transacciones) { + let sumaCredito = 0, sumDebito = 0; + let mayor = { + id: null, monto: -Infinity + } + + const conteo = { + 'Crédito': 0, 'Débito': 0 + }; + + for (const t of transacciones) { + // Si es que no exite pasa este indice + if (!(t.tipo in conteo)) continue; + // COntamos cada tarjeta + conteo[t.tipo]++; + + // + t.tipo === 'Crédito' ? + sumaCredito += t.monto : + sumDebito += t.monto; + + if (t.monto > mayor.monto) { + mayor = { id: t.id, monto: t.monto }; + } + + } + + return { + balance: sumaCredito - sumDebito, + mayor, + conteo + }; +} + + +function mostrarInformacion({ balance, mayor, conteo }) { + console.log("***************************") + console.log('* Reporte de Transacciones *'); + console.log("**********************************************************") + console.log(`* Balance Final: ${balance.toFixed(2)}`); + console.log(`* Transacción de Mayor Monto: ID ${String(mayor.id).padStart(3)} — ${mayor.monto.toFixed(2)}`); + console.log(`* Conteo de Transacciones: Crédito: ${String(conteo['Crédito']).padStart(2)} Débito: ${String(conteo['Débito']).padStart(2)}`); + console.log("**********************************************************") +} + +const transacciones = leerArchivo(ruta); +const reporte = procesarLogica(transacciones); +mostrarInformacion(reporte); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..fe4e5ed --- /dev/null +++ b/package-lock.json @@ -0,0 +1,359 @@ +{ + "name": "interbank-academy-25", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "interbank-academy-25", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "nodemon": "^3.1.9" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "license": "ISC", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "license": "MIT" + }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "license": "MIT", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "license": "MIT" + }, + "node_modules/debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", + "license": "ISC" + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "license": "MIT", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/nodemon": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.9.tgz", + "integrity": "sha512-hdr1oIb2p6ZSxu3PB2JWWYS7ZQ0qvaZsc3hK8DR8f02kRzc8rjYmxAIvdz+aYC+8F2IjNaB7HMcSDg8nQpJxyg==", + "license": "MIT", + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^4", + "ignore-by-default": "^1.0.1", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", + "license": "MIT" + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "license": "MIT", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/semver": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", + "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/simple-update-notifier": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", + "license": "MIT", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "license": "MIT", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/touch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", + "integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==", + "license": "ISC", + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", + "license": "MIT" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..2f10357 --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "interbank-academy-25", + "version": "1.0.0", + "description": "Prueba tecnica", + "keywords": [ + "prueba", + "tecnica", + "interbank", + "nodekjs" + ], + "homepage": "https://github.com/M4rckR/interbank-academy-25#readme", + "bugs": { + "url": "https://github.com/M4rckR/interbank-academy-25/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/M4rckR/interbank-academy-25.git" + }, + "license": "ISC", + "author": "Marcos Romero", + "type": "commonjs", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node index.js", + "dev": "nodemon --watch index.js --watch transacciones.csv index.js" + }, + "dependencies": { + "nodemon": "^3.1.9" + } +} From 62c45569380b8aafd60700dd7a470a3f066d11c2 Mon Sep 17 00:00:00 2001 From: Marck Romero <121461431+M4rckR@users.noreply.github.com> Date: Fri, 25 Apr 2025 01:56:06 -0500 Subject: [PATCH 2/2] Update README.md --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index e69de29..f67d42e 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,34 @@ +# Resolucion para los balances + +Este pequeño script en Node.js permite leer un archivo `.csv` con las transacciones bancarias, generando el resumen que muestra lo siguiente: + +- El balance final (Créditos - Débitos) +- La transacción de mayor monto +- El conteo de Créditos y Débitos + +--- + +## Requerimientos + +- Tener **Node.js** y **npm** instalados + +--- + +## Instalación + +3. Instala las dependencias (solo use nodemon): + + ```bash + npm install + +--- + +## Uso + +4. Ejecutamos el programa + + ```bash + npm run dev + +5. Una vez ejecutado el comando podremos visualizar el resultado + ![image](https://github.com/user-attachments/assets/98d3a041-5aea-43b4-ac4e-6fc0f19fd745)