Use Weather API and sort it by date

I'm trying to filter the array by date and then make a component for each day. Big hurdle for me are that the dates are displayed in UTC and I'm not sure how to turn that into a use-able format to loop through. The goal, unless someone suggests a more efficient approach, is to be able to group the date data, call that array (i.e firstDay[0] ) and loop through those to find the max temp of the day, humidity avg, etc. But I think the first step is to sort by date. I.e fiveDays[0].maxtemp

The JSON https://api.openweathermap.org/data/2.5/forecast?q=Austin,USA&appid=583f803dfc6a7f2f96ff9957c330c2b0&units=imperial

            var firstDay = [];
            var firstDayVar;
            for (i = 0; i < items.list.length; i++){
                let item = items.list[i].dt
                let date = new Date(item*1000)
                let dateNumber = date.getDate()
                let date_text = items.list[i].dt_txt
                // Thought this would be useful to organize by but not really applicable?
                let dateString = date_text.substring(0,10)


                console.log(dateString)
                //outputs yyyy-mm-dd
                if (firstDayVar === undefined){
                    firstDayVar = dateNumber
                } else if (firstDayVar !== dateNumber) {
                    firstDayVar = dateNumber
                    firstDay.push(firstDayVar);
            }
        }

4 answers

  • answered 2019-09-22 00:12 joyBlanks

    This is how I have grouped your data based on dates. Now you can loop them based on dates, Each date has an array of original object from your api list attribute.

    The api gives you array items of [DATE]_[TIME], Our Goal is to group same dates in a dictionary of [DATE], where each individual date will contain a list of original items (for that particular date)

    [ D1.T1, D1.T2, D2.T1, D3.T1, D3.T2, D3.T3 ] // Original Array of items

    .

    { D1: [D1.T1, D1.T2], D2: [D2.T1], D3: [D3.T1, D3.T2, D3.T3] } // Object grouped items by date

    If you look closely the idea is to keep your data safe so you have your original structure safe. Now then you loop the keys of your grouped Data you can access all items for a single date.

    fetch('https://api.openweathermap.org/data/2.5/forecast?q=Austin,USA&appid=583f803dfc6a7f2f96ff9957c330c2b0&units=imperial').then(response => response.json()).then(data => {
      const groupedData = data.list.reduce((days, row) => {
        const date = row.dt_txt.split(' ')[0];
        days[date] = [...(days[date] ? days[date]: []), row];
        return days;
      }, {});
      
      for(let date of Object.keys(groupedData)){
        console.log('Date:', date); 
        // current date -> date
        // original items array for this date -> groupedData[date]
        console.log('RowCount:', groupedData[date].length);
        console.log('MaxTemp:', getMax(groupedData[date], 'temp_max'));
        console.log('MinTemp:', getMin(groupedData[date], 'temp_min'));
        console.log('MaxHumidity:', getMax(groupedData[date], 'humidity'));
        
        console.log('\n\n');
      }
    });
    
    function getMax(arr, attr){
      return Math.max.apply(Math, arr.map(item => item.main[attr]));
    }
    
    function getMin(arr, attr){
      return Math.min.apply(Math, arr.map(item => item.main[attr]));
    }

    Since most of your data is in main attribute inside the list I made 2 helper functions that will compare all items and get the max and min for the passed attribute eg: temp_max, temp_min, humidity etc. You can get your own custom methods if you like.

    Hope this helps!

  • answered 2019-09-22 00:13 Destino Dello

    I am not sure if i am getting you but from the look of it the data from the weather API is already order in Ascending order by date thanks to the dt: key all you need to do is to render your components from the list

    list.map(day => <MyAwesomeComponent 
                       maxTemp={day.main.temp_max} 
                       humidityAvg={day.main.humidity}  />)
    

  • answered 2019-09-22 00:34 slye

    To get an array containing only the objects with a particular dateString (eg "2019-09-23"), I would use the Array.prototype.filter method and the String.prototype.includes method to return only objects whose dt_text includes the dateString:

    (where list is the array returned from the API)
    
    var firstDayList = list.filter(item => item.dt_txt.includes("2019-09-23"))
    
    

  • answered 2019-09-22 00:49 Lucas Bernalte

    I think with a functional approach you can get benefit of the simplicity of the reading and in case your needs change, easily identify where to place the change in code.

    In the snippet below, I tried to:

    • get the array data
    • group by day of the year
    • get max temperature of each day

    Of course output data structure can be of your choice. If you read the composition, you would only need to change the last function that returns the data in order to change it.

    I created some functions that would help me through this process although you could import some functional library like Ramda without having to code all of these functions by yourself. Hope it helps!

    const data = {"cod":"200","message":0.0182,"cnt":40,"list":[{"dt":1569110400,"main":{"temp":82.89,"temp_min":82.88,"temp_max":82.89,"pressure":1013.51,"sea_level":1013.51,"grnd_level":980.71,"humidity":70,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"clouds":{"all":17},"wind":{"speed":9.04,"deg":156.373},"rain":{"3h":0.937},"sys":{"pod":"n"},"dt_txt":"2019-09-22 00:00:00"},{"dt":1569121200,"main":{"temp":77.63,"temp_min":77.63,"temp_max":77.63,"pressure":1015.99,"sea_level":1015.99,"grnd_level":983.15,"humidity":82,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":9.33,"deg":155.707},"sys":{"pod":"n"},"dt_txt":"2019-09-22 03:00:00"},{"dt":1569132000,"main":{"temp":75.42,"temp_min":75.41,"temp_max":75.42,"pressure":1015.25,"sea_level":1015.25,"grnd_level":982.17,"humidity":87,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":9.62,"deg":161.426},"sys":{"pod":"n"},"dt_txt":"2019-09-22 06:00:00"},{"dt":1569142800,"main":{"temp":73.9,"temp_min":73.9,"temp_max":73.91,"pressure":1015.59,"sea_level":1015.59,"grnd_level":982.35,"humidity":91,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"clouds":{"all":20},"wind":{"speed":8.12,"deg":168.281},"sys":{"pod":"n"},"dt_txt":"2019-09-22 09:00:00"},{"dt":1569153600,"main":{"temp":73.08,"temp_min":73.08,"temp_max":73.08,"pressure":1015.14,"sea_level":1015.14,"grnd_level":982.18,"humidity":93,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":45},"wind":{"speed":6.73,"deg":167.593},"sys":{"pod":"n"},"dt_txt":"2019-09-22 12:00:00"},{"dt":1569164400,"main":{"temp":79,"temp_min":79,"temp_max":79,"pressure":1016.86,"sea_level":1016.86,"grnd_level":983.86,"humidity":78,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":16},"wind":{"speed":9.69,"deg":178.215},"sys":{"pod":"d"},"dt_txt":"2019-09-22 15:00:00"},{"dt":1569175200,"main":{"temp":85.01,"temp_min":85.01,"temp_max":85.01,"pressure":1015.13,"sea_level":1015.13,"grnd_level":982.73,"humidity":62,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":42},"wind":{"speed":9.01,"deg":196.503},"sys":{"pod":"d"},"dt_txt":"2019-09-22 18:00:00"},{"dt":1569186000,"main":{"temp":87.89,"temp_min":87.89,"temp_max":87.89,"pressure":1012.88,"sea_level":1012.88,"grnd_level":980.86,"humidity":53,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":35},"wind":{"speed":8.32,"deg":195.654},"sys":{"pod":"d"},"dt_txt":"2019-09-22 21:00:00"},{"dt":1569196800,"main":{"temp":83.03,"temp_min":83.03,"temp_max":83.03,"pressure":1012.49,"sea_level":1012.49,"grnd_level":980.17,"humidity":63,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"clouds":{"all":22},"wind":{"speed":4.74,"deg":193.203},"sys":{"pod":"n"},"dt_txt":"2019-09-23 00:00:00"},{"dt":1569207600,"main":{"temp":78.32,"temp_min":78.32,"temp_max":78.32,"pressure":1014.7,"sea_level":1014.7,"grnd_level":981.95,"humidity":70,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":4.61,"deg":162.944},"sys":{"pod":"n"},"dt_txt":"2019-09-23 03:00:00"},{"dt":1569218400,"main":{"temp":76.21,"temp_min":76.21,"temp_max":76.21,"pressure":1015.25,"sea_level":1015.25,"grnd_level":982.44,"humidity":83,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":2},"wind":{"speed":8.75,"deg":165.85},"sys":{"pod":"n"},"dt_txt":"2019-09-23 06:00:00"},{"dt":1569229200,"main":{"temp":73.96,"temp_min":73.96,"temp_max":73.96,"pressure":1015.75,"sea_level":1015.75,"grnd_level":982.71,"humidity":89,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":5.75,"deg":180.824},"sys":{"pod":"n"},"dt_txt":"2019-09-23 09:00:00"},{"dt":1569240000,"main":{"temp":71.87,"temp_min":71.87,"temp_max":71.87,"pressure":1015.53,"sea_level":1015.53,"grnd_level":982.54,"humidity":97,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":3},"wind":{"speed":4.36,"deg":186.139},"sys":{"pod":"n"},"dt_txt":"2019-09-23 12:00:00"},{"dt":1569250800,"main":{"temp":79.65,"temp_min":79.65,"temp_max":79.65,"pressure":1017.18,"sea_level":1017.18,"grnd_level":984.35,"humidity":77,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":39},"wind":{"speed":7.11,"deg":193.795},"sys":{"pod":"d"},"dt_txt":"2019-09-23 15:00:00"},{"dt":1569261600,"main":{"temp":85.73,"temp_min":85.73,"temp_max":85.73,"pressure":1015.9,"sea_level":1015.9,"grnd_level":983.44,"humidity":57,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":57},"wind":{"speed":7.2,"deg":184.806},"sys":{"pod":"d"},"dt_txt":"2019-09-23 18:00:00"},{"dt":1569272400,"main":{"temp":88.16,"temp_min":88.16,"temp_max":88.16,"pressure":1013.63,"sea_level":1013.63,"grnd_level":981.49,"humidity":53,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":2},"wind":{"speed":8.66,"deg":184.39},"sys":{"pod":"d"},"dt_txt":"2019-09-23 21:00:00"},{"dt":1569283200,"main":{"temp":82.85,"temp_min":82.85,"temp_max":82.85,"pressure":1013,"sea_level":1013,"grnd_level":980.58,"humidity":65,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":1},"wind":{"speed":4.88,"deg":199.248},"sys":{"pod":"n"},"dt_txt":"2019-09-24 00:00:00"},{"dt":1569294000,"main":{"temp":78.71,"temp_min":78.71,"temp_max":78.71,"pressure":1014.56,"sea_level":1014.56,"grnd_level":981.68,"humidity":72,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":5.86,"deg":165.386},"sys":{"pod":"n"},"dt_txt":"2019-09-24 03:00:00"},{"dt":1569304800,"main":{"temp":76.09,"temp_min":76.09,"temp_max":76.09,"pressure":1014.45,"sea_level":1014.45,"grnd_level":981.57,"humidity":85,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":1},"wind":{"speed":9.28,"deg":176.517},"sys":{"pod":"n"},"dt_txt":"2019-09-24 06:00:00"},{"dt":1569315600,"main":{"temp":74.21,"temp_min":74.21,"temp_max":74.21,"pressure":1013.85,"sea_level":1013.85,"grnd_level":980.82,"humidity":88,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":7.74,"deg":179.718},"sys":{"pod":"n"},"dt_txt":"2019-09-24 09:00:00"},{"dt":1569326400,"main":{"temp":72.42,"temp_min":72.42,"temp_max":72.42,"pressure":1013.93,"sea_level":1013.93,"grnd_level":980.82,"humidity":95,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":4.63,"deg":182.266},"sys":{"pod":"n"},"dt_txt":"2019-09-24 12:00:00"},{"dt":1569337200,"main":{"temp":79.25,"temp_min":79.25,"temp_max":79.25,"pressure":1014.69,"sea_level":1014.69,"grnd_level":981.9,"humidity":78,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":30},"wind":{"speed":8.63,"deg":183.908},"sys":{"pod":"d"},"dt_txt":"2019-09-24 15:00:00"},{"dt":1569348000,"main":{"temp":85.81,"temp_min":85.81,"temp_max":85.81,"pressure":1013.17,"sea_level":1013.17,"grnd_level":980.88,"humidity":60,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":53},"wind":{"speed":9.42,"deg":187.144},"rain":{"3h":0.125},"sys":{"pod":"d"},"dt_txt":"2019-09-24 18:00:00"},{"dt":1569358800,"main":{"temp":87.82,"temp_min":87.82,"temp_max":87.82,"pressure":1010.22,"sea_level":1010.22,"grnd_level":977.99,"humidity":53,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":42},"wind":{"speed":9.95,"deg":182.088},"sys":{"pod":"d"},"dt_txt":"2019-09-24 21:00:00"},{"dt":1569369600,"main":{"temp":83.21,"temp_min":83.21,"temp_max":83.21,"pressure":1009.42,"sea_level":1009.42,"grnd_level":977.01,"humidity":64,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":36},"wind":{"speed":7.67,"deg":177.945},"sys":{"pod":"n"},"dt_txt":"2019-09-25 00:00:00"},{"dt":1569380400,"main":{"temp":78.07,"temp_min":78.07,"temp_max":78.07,"pressure":1011.25,"sea_level":1011.25,"grnd_level":978.5,"humidity":73,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":2},"wind":{"speed":6.69,"deg":164.21},"sys":{"pod":"n"},"dt_txt":"2019-09-25 03:00:00"},{"dt":1569391200,"main":{"temp":74.71,"temp_min":74.71,"temp_max":74.71,"pressure":1010.9,"sea_level":1010.9,"grnd_level":977.86,"humidity":76,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":1},"wind":{"speed":8.99,"deg":168.103},"sys":{"pod":"n"},"dt_txt":"2019-09-25 06:00:00"},{"dt":1569402000,"main":{"temp":71.69,"temp_min":71.69,"temp_max":71.69,"pressure":1011.28,"sea_level":1011.28,"grnd_level":978.47,"humidity":84,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":37},"wind":{"speed":5.17,"deg":194.313},"sys":{"pod":"n"},"dt_txt":"2019-09-25 09:00:00"},{"dt":1569412800,"main":{"temp":70.28,"temp_min":70.28,"temp_max":70.28,"pressure":1011.42,"sea_level":1011.42,"grnd_level":978.5,"humidity":86,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":37},"wind":{"speed":5.46,"deg":186.551},"sys":{"pod":"n"},"dt_txt":"2019-09-25 12:00:00"},{"dt":1569423600,"main":{"temp":77.56,"temp_min":77.56,"temp_max":77.56,"pressure":1011.79,"sea_level":1011.79,"grnd_level":979,"humidity":71,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":8.12,"deg":193.902},"sys":{"pod":"d"},"dt_txt":"2019-09-25 15:00:00"},{"dt":1569434400,"main":{"temp":86.92,"temp_min":86.92,"temp_max":86.92,"pressure":1010.36,"sea_level":1010.36,"grnd_level":977.95,"humidity":50,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":10.2,"deg":185.353},"sys":{"pod":"d"},"dt_txt":"2019-09-25 18:00:00"},{"dt":1569445200,"main":{"temp":88.89,"temp_min":88.89,"temp_max":88.89,"pressure":1007.85,"sea_level":1007.85,"grnd_level":975.65,"humidity":45,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":70},"wind":{"speed":9.8,"deg":182.987},"sys":{"pod":"d"},"dt_txt":"2019-09-25 21:00:00"},{"dt":1569456000,"main":{"temp":83.55,"temp_min":83.55,"temp_max":83.55,"pressure":1008.24,"sea_level":1008.24,"grnd_level":975.81,"humidity":57,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":42},"wind":{"speed":5.12,"deg":185.16},"sys":{"pod":"n"},"dt_txt":"2019-09-26 00:00:00"},{"dt":1569466800,"main":{"temp":78.68,"temp_min":78.68,"temp_max":78.68,"pressure":1010.16,"sea_level":1010.16,"grnd_level":977.2,"humidity":60,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":9},"wind":{"speed":4.16,"deg":150.313},"sys":{"pod":"n"},"dt_txt":"2019-09-26 03:00:00"},{"dt":1569477600,"main":{"temp":74.57,"temp_min":74.57,"temp_max":74.57,"pressure":1010.71,"sea_level":1010.71,"grnd_level":977.75,"humidity":79,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"clouds":{"all":18},"wind":{"speed":10.51,"deg":175.199},"sys":{"pod":"n"},"dt_txt":"2019-09-26 06:00:00"},{"dt":1569488400,"main":{"temp":72.6,"temp_min":72.6,"temp_max":72.6,"pressure":1010.46,"sea_level":1010.46,"grnd_level":977.47,"humidity":85,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":9},"wind":{"speed":7.54,"deg":186.554},"sys":{"pod":"n"},"dt_txt":"2019-09-26 09:00:00"},{"dt":1569499200,"main":{"temp":70.79,"temp_min":70.79,"temp_max":70.79,"pressure":1010.83,"sea_level":1010.83,"grnd_level":977.8,"humidity":90,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":5},"wind":{"speed":4.88,"deg":179.185},"sys":{"pod":"n"},"dt_txt":"2019-09-26 12:00:00"},{"dt":1569510000,"main":{"temp":78.81,"temp_min":78.81,"temp_max":78.81,"pressure":1011.75,"sea_level":1011.75,"grnd_level":978.79,"humidity":71,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":26},"wind":{"speed":6.93,"deg":183.796},"sys":{"pod":"d"},"dt_txt":"2019-09-26 15:00:00"},{"dt":1569520800,"main":{"temp":86.98,"temp_min":86.98,"temp_max":86.98,"pressure":1010.72,"sea_level":1010.72,"grnd_level":977.99,"humidity":49,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":56},"wind":{"speed":8.81,"deg":158.347},"sys":{"pod":"d"},"dt_txt":"2019-09-26 18:00:00"},{"dt":1569531600,"main":{"temp":89.14,"temp_min":89.14,"temp_max":89.14,"pressure":1007.34,"sea_level":1007.34,"grnd_level":974.86,"humidity":42,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":25},"wind":{"speed":10.07,"deg":167.638},"sys":{"pod":"d"},"dt_txt":"2019-09-26 21:00:00"}],"city":{"id":4671654,"name":"Austin","coord":{"lat":30.2711,"lon":-97.7437},"country":"US","population":790390,"timezone":-18000,"sunrise":1569068318,"sunset":1569112179}}
    
    /**
    * FUNCTIONS TO HELP IN THE COMPOSITION
    */
    const pluck = prop => obj => obj[prop];
    const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x);
    const map = f => arr => arr.map(f)
    const oMap = f => o => Object.assign({}, ...Object.keys(o).map(k => ({ [k]: f(o[k]) })));
    const groupBy = prop => arr => {
      return arr.reduce(function(groups, item) {
        const val = item[prop];
        groups[val] = groups[val] || [];
        groups[val].push(item);
        return groups;
      }, {});
    };
    
    /**
    * Function that takes an entry of the raw data array and adds a _day with the dd/mm/yyyy
    */
    const addDay = item => ({...item, _day: (new Date(item.dt*1000)).toLocaleDateString()});
    
    /**
    * Function that takes an array of entries and get the max temperature in it
    */
    const getMaxTempArr = arr => {
      const maxTemp = arr.reduce((acc, val) => {
        if (val.main.temp_max > acc) {
          acc = val.main.temp_max;
        }
        return acc;
      }, 0);
      return maxTemp;
    }
    
    const program = pipe(
      pluck('list'),
      map(addDay),
      groupBy('_day'),
      oMap(getMaxTempArr)
    )
    
    console.log(program(data))