Understanding Javascript Reduce and Logical OR operator

Hi, I am trying to wrap my head around the below code. From what I’ve read about the reduce method, it returns a single value from an array. But, is the below code returning an object instead? I don’t understand what the author of the code trying to do with the OR logical operator. Can someone please break this down? Thank you.

let result = data.reduce((result, d) => {
        let currentData = result[d.AirlineID] || {
            "AirlineID": d.AirlineID,
            "AirlineName": d.AirlineName,
            "Count": 0
        }

        return result;
    }, {})

What is the input (data)? It would help on explaining this. It doesn’t quite make sense at the minute, nothing is happening with currentData, afaics the end result is always an object with no properties (??)

Here it is as an imperative loop, hopefully easier for you to understand the mechanics:

const result = {};

for (const d of data) {
  let currentData;
  // if result has the a property with the key
  // of the current ID, set currentData[id]
  // to that object:
  if (d.AirlineID in result) {
    currentData = d.AirlineID;
  } else {
    currentData = {
      "AirlineID": d.AirlineID,
      "AirlineName": d.AirlineName,
      "Count": 0,
    };
  }
}

return result;

I think it should look more this (go through the array of data, only adding to the output object if the AirlineID hasn’t been used). But you’d need to show the input and explain the expected output, as this still doesn’t quite make sense:

const result = {};

for (const d of data) {
  if (!(d.AirlineID in result)) {
    result [d.AirlineID] = {
      "AirlineID": d.AirlineID,
      "AirlineName": d.AirlineName,
      "Count": 0,
    };
  }
}

return result;

Or

data.reduce((result, d) => {
  result[d.AirlineID] = result[d.AirlineID] || {
    "AirlineID": d.AirlineID,
    "AirlineName": d.AirlineName,
    "Count": 0,
  };
  return result;
}, {});

Thank you for your feedback DanCouper. Below is the first 3 lines of the source data.

ID,AirlineID,AirlineName,AirlineCountry,SourceAirportID,SourceAirportCode,SourceAirport,SourceCity,SourceCountry,SourceLatitude,SourceLongitude,DestAirportID,DestCode,DestAirport,DestCity,DestCountry,DestLatitude,DestLongitude
1,24,American Airlines,United States,4355,ABE,Lehigh Valley International Airport,Allentown,United States,40.65209961,-75.44080353,3876,CLT,Charlotte Douglas International Airport,Charlotte,United States,35.2140007,-80.94309998
2,24,American Airlines,United States,4355,ABE,Lehigh Valley International Airport,Allentown,United States,40.65209961,-75.44080353,3752,PHL,Philadelphia International Airport,Philadelphia,United States,39.87189865,-75.2410965
3,24,American Airlines,United States,3718,ABI,Abilene Regional Airport,Abilene,United States,32.41130066,-99.68190002,3670,DFW,Dallas Fort Worth International Airport,Dallas-Fort Worth,United States,32.896801,-97.03800201

Below is all of the code in it’s entirety. It’s part of a self study assignement on using D3 to analyze a csv file with flight data. I was able to work the showData function could probably do the rest of it. However, I wanted to fully understand how and why all aspects of the code works. Thank you.

<script>
        let store = {};
        
        function loadData() {
            //TODO 1: Add the code to load the CSV file named "routes.csv" | 1 Line
            let promise = d3.csv("routes.csv");

            return promise.then(routes => {
                //TODO 2: Save the routes into our store variable;
                store.routes = routes;
                return store;
            })
        }

        function groupByAirline(data) {
            //Iterate over each route, producing a dictionary where the keys are the ailines ids and the values are the information of the airline.
            let result = data.reduce((result, d) => {

                let currentData = result[d.AirlineID] || {
                    "AirlineID": d.AirlineID,
                    "AirlineName": d.AirlineName,
                    "Count": 0
                }
                
                //TODO: Increment the count (number of routes) of ariline.
                // currentData.Count += 

                //TODO: Save the updated information in the dictionary using the airline id as key.

                // result[d.AirlineID] = 

                return result;
            }, {})

            //We use this to convert the dictionary produced by the code above, into a list, that will make it easier to create the visualization. 
            // result = Object.keys(result).map(key => result[key])
            // result = //TODO: Sort the data in descending order of count.

            return result;
        }

        function showData() {
            //Get the routes from our store variable
            let routes = store.routes
            console.log(routes);
            // Compute the number of routes per airline.
            let airlines = groupByAirline(store.routes);
            console.log(airlines)
        }

        loadData().then(showData);
    </script>