ebox es6(javascript)
Sat Oct 05 2024 03:53:31 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
1)var fs = require('fs');
// Read the input from the file
var input = fs.readFileSync('concat.txt').toString().trim();
// Split the input into two parts using the comma
var [firstPart, secondPart] = input.split(',');
// Create arrays from the split parts, trimming each line
var firstArray = firstPart.split('\n').map(line => line.trim()).map(Number);
var secondArray = secondPart.split('\n').map(line => line.trim()).map(Number);
// Check for and filter out any NaN values from both arrays
firstArray = firstArray.filter(num => !isNaN(num));
secondArray = secondArray.filter(num => !isNaN(num));
secondArray.shift();
// Combine the arrays using the spread operator
var combinedArray = [...firstArray, ...secondArray];
// Print the output as a space-separated string
console.log(combinedArray.join(' '));
2)var fs = require('fs');
var input = fs.readFileSync('input.txt').toString().trim();
var numbers = input.split('\n').map(Number);
var filteredNumbers = numbers.filter(num => num > 5);
filteredNumbers.forEach(num => console.log(num));
3)var fs = require('fs');
// Read the input from the file
var input = fs.readFileSync('input.txt').toString().trim();
// Split the input into an array of numbers
var numbers = input.split('\n').map(Number);
// Sort the array in ascending order
numbers.sort((a, b) => a - b);
// Print the output, each number on a new line
numbers.forEach(num => console.log(num));
content_copyCOPY
Comments