Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
how to use fs for saving and loading matrices to and from text files?

I have such a problem. I need to create a pair of functions for saving and loading matrices to and from text files.

  1. I need to creat a fnction saveMatrixToFile(matrix, path), that writes the contents of the argument matrix into a file located at the given path.
  2. then to create a fnction loadMatrixFromFile(path) function, that returns a matrix filled with the contents of a file that has been created using the saveMatrixToFile() function.

Here is a part of my code, but I'm not sure if it's right or not.

const fs = require('fs');
function saveToTextFile(matrix) {  
fs.writeFile("./new.txt", matrix, (err) => {
    if(err){
        console.log(err);
    }
    else {
        console.log("saved to textfile1");
    }
});

console.log("next");
}
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

How are your matrices defined? Would a simple

JSON.stringify(matrix);

and

JSON.parse(matrixJsonStringFromFile);

already do the trick?

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda