Currently, I have written below function to filter the items based on the month and return in Array and I have used below login.
Can someone help is there any way I can filter even more easily using datejs or moment js using for loop in more efficient way
Here I am getting date in the format of 2/Jan/17
and filtering based on includes
method
Thanks in advance!!
Javascript
function getMonthlyCount() {
return yearlyExecution()
.then(function(myitems) {
monthlyDataForGraph = [];
var janFinalCount = febFinalCount = marFinalCount = aprFinalCount = mayFinalCount = junFinalCount = julFinalCount = augFinalCount = sepFinalCount = octFinalCount = novFinalCount = decFinalCount = 0;
myitems.forEach(function(items) {
releasename = items[0].cycleName;
janData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Jan/17"))
return inputs;
});
febData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Feb/17"))
return inputs;
});
marData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Mar/17"))
return inputs;
});
aprData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Apr/17"))
return inputs;
});
mayData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("May/17"))
return inputs;
});
junData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Jun/17"))
return inputs;
});
julData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Jul/17"))
return inputs;
});
augData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Aug/17"))
return inputs;
});
sepData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Sep/17"))
return inputs;
});
octData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Oct/17"))
return inputs;
});
novData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Nov/17"))
return inputs;
});
decData = $filter('filter')(items, function(inputs) {
if (inputs.executedOn.includes("Dec/17"))
return inputs;
});
janFinalCount = janFinalCount + janData.length;
febFinalCount = febFinalCount + febData.length;
marFinalCount = marFinalCount + marData.length;
aprFinalCount = aprFinalCount + aprData.length;
mayFinalCount = mayFinalCount + mayData.length;
junFinalCount = junFinalCount + junData.length;
julFinalCount = julFinalCount + julData.length;
augFinalCount = augFinalCount + augData.length;
sepFinalCount = sepFinalCount + sepData.length;
octFinalCount = octFinalCount + octData.length;
novFinalCount = novFinalCount + novData.length;
decFinalCount = decFinalCount + decData.length;
});
monthlyDataForGraph = [janFinalCount, febFinalCount, marFinalCount, aprFinalCount, mayFinalCount, junFinalCount, julFinalCount, augFinalCount, sepFinalCount, octFinalCount, novFinalCount, decFinalCount];
console.log('Monthly Data For Graph', monthlyDataForGraph);
return monthlyDataForGraph;
});
}
Source: AngularJS
from Angular Questions https://angularquestions.com/2017/10/10/optimize-the-js-function-to-filter-the-data-based-on-month/
via @lzomedia #developer #freelance #web #lzomedia.com
No comments:
Post a Comment