I am currently trying to create a function which dynamically changes values of an array in a map. This function is intended to create a new element in the array on each full loop, to represent a new instance to be counted.
The function is meant to count how many visitors to a country there are every day. This is done throgh a map, with the keys being the country and the values being a list of visitors. Each element is how many visitors there were in a specific day.
Where Map:
var countries = new Map(); ('England', [0]); ('France', [0]); ('Spain', [0]); ('Poland', [0]); ('Germany', [0]); ('Russia', [0]); For the code:
for(var day = 0; day < daysBack; day++){ var dateToFind = (currentDate.date() + " / " + currentDate.month() + " / " + currentDate.year()); var detectionsOnDate = getActivity(dateToFind ); // Returns an array of locations visited, each visit is a new element // eg. ["France", "France", "England", "France"] for(var detectionLocation of detectionsOnDate){ for(var[location, visits] of countries ){ if(location == detectionLocation){ countries.set(location, visits[day]++); } } } currentDate.subtract(1, 'days'); } The result I am looking for is a map similar to:
{ ('England', [242,235,853,122,512]); ('France', [241,621,173,173,512]); ('Spain', [62,235,213,465,126]); ('Poland', [734,163,856,354,142]); ('Germany', [234,235,643,237,512]); ('Russia', [174,200,136,107,164]); } In my idea of the logic, this should create a new element in the value every time a new loop of 'day' is done. On each loop of day the same element in the map should be updated.
I'm relatively new to JS so I'm sorry if this is an easy fix, still finding my way around. Any help is appriciated. Thanks.