Skip to content

Instantly share code, notes, and snippets.

@Dobby233Liu
Created February 3, 2020 01:37
Show Gist options
  • Save Dobby233Liu/fe2c363e52c00392da70f40af9012864 to your computer and use it in GitHub Desktop.
Save Dobby233Liu/fe2c363e52c00392da70f40af9012864 to your computer and use it in GitHub Desktop.
index = [
{
obj: window.getListByCountryTypeService1,
data: {
creationDate: "createTime",
modifiedDate: "modifyTime",
op: "operator"
}
},
{
obj: window.getListByCountryTypeService2,
data: {
creationDate: "createTime",
modifiedDate: "modifyTime",
op: "operator"
}
},
{
obj: window.getIndexRecommendList,
data: {
creationDate: "createTime",
modifiedDate: "modifyTime",
op: "operator"
}
},
{
obj: window.getTimelineService,
data: {
creationDate: "createTime",
modifiedDate: "modifyTime",
op: "dataInfoOperator"
}
}]
myCompound = {
creationDate: [],
modifiedDate: [],
op: []
};
shouldConvertToDate = v => v.toLowerCase().indexOf("date") >= 0 || v.toLowerCase().indexOf("time") >= 0;
washCompound = function (data, curIndex) {
var ret = Array.from(new Set(data[curIndex])).filter(Boolean);
if(!shouldConvertToDate(curIndex)) return ret; // fun starts down here
var isJSDate = v => !isNaN(v) && v.toString().length == 13;
var isUnixTime = v => !isNaN(v) && v.toString().length == 10;
ret = ret.map(x => (!isJSDate(x) && !isUnixTime(x) ? x : new Date(x * (isUnixTime(x) ? 1000 : 1))));
return ret;
}
for(i of index) {
for(i2 in i.data) {
for(foundStuff in i.obj) {
foundStuff = i.obj[foundStuff];
gotData = foundStuff[i.data[i2]];
myCompound[i2].push(gotData);
myCompound[i2] = washCompound(myCompound, i2); // wash data often
}
}
}
myCompound;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment