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

143
Visualizações
why the order of loop changes by parsing data in sqlite database

an xml document is edited using a function. First, all duplicate files are removed. Then the content is entered into a sql database. For this I run a loop that corresponds to the length of the xml elements (here already converted to json). When I look at the content of the table in the database, I see that the order of the entries does not correspond to the order of the array. So within the database query of my server I printed the run variable i and saw that it starts at 0 but 2,3,1 are appended to the end in this order. Unfortunately I don't understand at all why this happens and hope that someone can help me here.

function extractquestions(filename){
    let questions = [];
    let sql_insert = 'INSERT INTO Fragen (Titel, Frage) values (?,?)';
     
    fs.readFile('./files/'+filename, function(err, data){
        if(err){
            throw err;
        }
        
        const xmlDataStr = data;
        const options = {
            ignoreAttributes: false,
            attributeNamePrefix : "attr_"
        };
        const parser = new XMLParser(options);
        const output = parser.parse(xmlDataStr);
        for(let i = 0; i<output.quiz.question.length; i++){
     
            //Here the needed Questions are filtered out of the xml (Json) data
            if(output.quiz.question[i].attr_type == "coderunner"){
                questions.push(output.quiz.question[i]);
            }
        }


        //Delete Duplicates from array
         const filteredQuestions = questions.reduce((acc, current) => {
            const x = acc.find(item => item.name.text === current.name.text);
            if (!x) {
                return acc.concat([current]);
            } else {
                return acc;
            }
        }, []);
        
        for(let i = 0; i<filteredQuestions.length; i++){
            db.run(sql_insert, filteredQuestions[i].name.text, filteredQuestions[i], (err, result)=>{
                console.log(i);
                if(err){
                    throw err;
                }
            });
        }
    });
}
about 4 years ago · Juan Pablo Isaza
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