Currently, I am working on a project in Javascript that involves processing a .dat file containing various data related to English Soccer teams. After extracting a Json from the file, I converted it into an array as follows:
[{"team":"Arsenal","f":"79","a":"36"},
{"team":"Liverpool","f":"67","a":"30"},
...
{"team":"Leicester","f":"30","a":"64"}]
This array contains the names of different soccer teams along with two values: goals scored (F) and goals conceded (A). The task at hand is to parse this array and perform the following operations:
- Calculate the difference between "a" and "f" for each team and add this value to the array;
- Determine the team with the smallest difference between goals scored and conceded.
However, I am currently stuck and unsure how to proceed with these operations.
I have managed to write some code up to this point:
const myFrom = document.getElementById("myForm");
const datFile = document.getElementById("datFile");
function fileToArray(text) {
...
}
myForm.addEventListener("submit", function (e) {
...
});
<form id="myForm">
<input type="file" id="datFile" accept=".dat" />
<br />
<input type="submit" value="Submit" />
</form>
Unfortunately, this is where I hit a roadblock in my progress.