Adding Dynamic Slides to a slider used by a client shifts its index, need to account for that so i wrote this simple code, but i think it's pretty lame, is there any way to improve it and accomplish the same output?
var slides = {
1: {
content: "",
group: 1
},
2: {
group: 1
},
3: {
content: "",
group: 1
},
4: {
content: "",
group: 2
},
5: {
content: "",
group: 3
},
6: {
content: "",
group: 3
},
7: {
content: "",
group: 3
},
8: {
content: "",
group: 4
},
9: {
content: "",
group: 4
},
10: {
content: "",
group: 4
},
11: {
content: "",
group: 5
},
12: {
content: "",
group: 5
}
};
var shiftCount = [],
shiftCounter = 0,
lastgroup, lastcount;
for (var slideIndex in slides) {
var group = parseInt(slides[slideIndex].group, 10);
if (group === 1) { //no shift caused by 1st group
shiftCount.push(0);
} else {
if (group !== lastgroup) { //stay on current group.
lastcount = shiftCount.length;
lastgroup = group;
shiftCount.push(shiftCount.length);
} else { //fill rest of array with repeated count and match length.
shiftCount.push(lastcount);
}
}
}
console.log(shiftCount);
Thanks!