Server gives me next array :
let reportsInDB = [
{comment:"asdasd", date:"13-02-2018", issueId:"1005"},
{comment:"asdasd", date:"14-02-2018", issueId:"1005"},
{comment:"asdasd", date:"15-02-2018", issueId:"1005"},
{comment:"qwe", date:"13-02-2018", issueId:"1006"},
{comment:"asd123123asd", date:"14-02-2018", issueId:"1006"},
{comment:"asd123123asd", date:"15-02-2018", issueId:"1006"},
{comment:"lalala", date:"15-02-2018", issueId:"1007"},
]
Is there a way to make next:
compare if object with today date has same comment as the "yesterday" object (of course same issueId of that objects) and push it (maybe push not whole object, just it issueId) to new array, arrRisk = [] for example, but if comments are same 3 days in a row - push to another array, arrIncident = [], for example.
So the final output should be something like next:
arrRisk = ["1006"]
arrIncident = ["1005]
Object with issueId 1007 shouldnt go to any of new arrays, because there is no same comment with its issueId yesterday or day before yesterday.
Also I got service variables, which should help to compare:
today = "15-02-2018"
yesterday = "14-02-2018"
beforeYesterday = "13-02-2018"
I was trying something like
reportsInDB.map(x => {
reportsInDB.map(r =>{
if( x.date === today &&
r.date === yesterday &&
x.issueId === r.issueId &&
x.comment === r.comment
){
reportsToRisk.push(r)
}
})
})
But output totally not what I need (e.g. I don`t need issueId 1005 push to riskArray) and double-triple cycles are not so good as I know...
That is what I try in jsfiddle
Hope my explanation what final result should be is clear.

returnwhen using.map()then.map()is the wrong methodmap()just for looping...reduceis the way to go. Do you need help writing it?.reducebut can`t get how to implement it, so it would be greate if you will help !