diff --git a/Desarrollo/t1/badIn.txt b/Desarrollo/t1/badIn.txt new file mode 100644 index 0000000..f545b93 --- /dev/null +++ b/Desarrollo/t1/badIn.txt @@ -0,0 +1,5 @@ +fed +1 +ooo +32332 +23232 diff --git a/Desarrollo/t1/in.txt b/Desarrollo/t1/in.txt new file mode 100644 index 0000000..c6fa778 --- /dev/null +++ b/Desarrollo/t1/in.txt @@ -0,0 +1,3 @@ +10 +42 +48 diff --git a/Desarrollo/t1/main.js b/Desarrollo/t1/main.js new file mode 100644 index 0000000..99e3841 --- /dev/null +++ b/Desarrollo/t1/main.js @@ -0,0 +1,38 @@ +/* +Consigna: +1- Bajar node.js +2- Tomar dos standart input de un archivo txt, sumarlos y mostrarlos dentro de otro txt +3- Ambos argumentos deben estar validados + +Uso: +$ node main.js out.txt +*/ + +process.stdin.setEncoding('utf8'); +if (process.stdin.isTTY) { + process.stdout.write("Missing stdin redirection"); + process.exit(1); +} + +let chunks = ""; + +process.stdin.on('data', (chunk) => { + chunks+= chunk; +}); + +process.stdin.on('end', () => { + const lines = chunks.trim().split(/\s+/); + + const numbers = lines.map(line => Number(line.trim())); + + numbers.forEach((x)=>{ + if (isNaN(x)){ + process.stdout.write("Invalid Input"); + process.exit(1); + } + }); + + const sum = numbers.reduce((acc, curr) => acc + curr, 0); + + process.stdout.write(`${sum}\n`); +}); diff --git a/Desarrollo/t1/run.sh b/Desarrollo/t1/run.sh new file mode 100644 index 0000000..8779722 --- /dev/null +++ b/Desarrollo/t1/run.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +echo "Running.." +node main.js out.txt + +echo "Running Missing Stdin.." +node main.js >out2.txt + +echo "Running Invalid Input" +node main.js out3.txt