Created
February 18, 2020 10:40
-
-
Save feilongfl/409dfadc44d1fe6ee81bfb159e8e8d9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function input(date,name1,name2){ | |
this.date = date; | |
this.name1 = name1; | |
this.name2 = name2; | |
this.hash = name1 + name2; | |
} | |
inputdata = Array.of(new input(1, 'a', 'b'),new input(2, 'a', 'b'),new input(3, 'a', 'b'),new input(4, 'a', 'c'),new input(5, 'a', 'c'),new input(6, 'a', 'b'),new input(7, 'a', 'b')) | |
function result(name1,name2,hash,start,end){ | |
this.name = name1; | |
this.name2 = name2; | |
this.start = start; | |
this.end = end; | |
this.hash = hash; | |
} | |
resultTemp = new result(inputdata[0].name1,inputdata[0].name2,inputdata[0].hash,inputdata[0].date,inputdata[0].date); | |
resultList = Array() | |
for (i = 1; i < inputdata.length; i++){ | |
if(resultTemp.hash != inputdata[i].hash){ | |
resultList.push(resultTemp); | |
resultTemp = new result(inputdata[0].name1,inputdata[i].name2,inputdata[i].hash,inputdata[i].date,inputdata[i].date); | |
} | |
resultTemp.end = inputdata[i].date; | |
} | |
resultList.push(resultTemp); | |
console.log(resultList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
input:
output: