Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
recopilar datos de un archivo de texto y analizar los datos recopilados para crear una matriz de objetos

Necesito ayuda Básicamente, tengo que recopilar algunos datos de un archivo de texto colocado en GitHub (algunos datos sobre algunos estudiantes que se ven así

Juan
Nueva York
123456456
Matemáticas
ben
California
3265455554
Filosofía
..... ..... .....

hay un total de 5 estudiantes), y tengo que analizar el archivo en la página web de esta manera usando una clase u objeto

Nombre: Juan
Dirección: Nueva York
Teléfono: 123456456
Curso: Matemáticas

Nombre: Ben
Dirección: California
Teléfono: 3265455554
Curso: Filosofía

Nombre: ....
Dirección: ....
Teléfono:.....
Curso: ....

y así.

La idea es usar funciones async/await en mi tarea, esto es lo que me dijo mi maestro.

 var button = document.getElementById("btn"); var loader = document.getElementById("loading"); var displayArea = document.getElementById("data"); button.addEventListener("click", function () { getData(); }) class Student { constructor(fullName, address, phone, course) { this.fullName = fullName; this.address = address; this.phone = phone; this.course = course; } getInfo() { return "Full Name: " + this.fullName + "\n" + "Address: " + this.address + "\n" + "Telephone: " + this.phone + "\n" + "Course: " + this.course; } } var studentName = new Student().fullName; var studentAddress = new Student().address; var studentPhone = new Student().phone; var studentCourse = new Student().course; var studentInfo = new Student().getInfo(); var studentData = [studentName, studentAddress, studentPhone, studentCourse] async function getData() { loader.style.display = "inline-block"; try { let response = await fetch(`https://v-dresevic.github.io/Advanced-JavaScript-Programming/data/students.txt`); if (response.status !== 200) { throw new Error("Error while reading file."); } let text = await response.text(); var res = text.split([3], "\n"); for (let i = 0; i <= res.length; i++) { } displayArea.innerHTML = res } catch (err) { displayArea.innerHTML = "Unknown Error " + err; } finally { loader.style.display = "none"; } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 async function getData(){ let response = await fetch(`https://v-dresevic.github.io/Advanced-JavaScript-Programming/data/students.txt`); if (response.status !== 200) { throw new Error("Error while reading file."); } let text = await response.text(); let arr = text.split("\n"); let result = arr.reduce((resultArray, item, index) => { const chunkIndex = Math.floor(index/4); if(!resultArray[chunkIndex]) { resultArray[chunkIndex] = [] } resultArray[chunkIndex].push(item.replace(/(.+)(\r)$/, '$1')); return resultArray }, []).map(d=>{ return {Name: d[0], Address: d[1], Phone: d[2], Course: d[3]}; }); return result; } async function func(){ let result = await getData(); console.log(result); } func();

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!