Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda