I created a customized function to create a responsive carousel with multiple images per slide. (Unfortunately, I couldn't get Owl Carousel to work on my Angular project, but that's not the focus here).
The number of images displayed per slide is determined by the current screen width.
Take a look at my code snippet:
imgsHistory = [
"../../assets/imgs/history/hist_01.png",
"../../assets/imgs/history/hist_02.png",
"../../assets/imgs/history/hist_03.png",
"../../assets/imgs/history/hist_04.png",
"../../assets/imgs/history/hist_05.png",
"../../assets/imgs/history/hist_06.png",
"../../assets/imgs/history/hist_07.png",
"../../assets/imgs/history/hist_08.png",
"../../assets/imgs/history/hist_09.png",
"../../assets/imgs/history/hist_10.png",
];
imgsHistoryArray = [];
resizeCarousel() {
let images = this.imgsHistory;
let cut = this.getCut();
this.imgsHistoryArray = [];
for (var i = 0; i < images.length; i = i + cut) {
this.imgsHistoryArray.push(images.slice(i, i + cut));
}
}
getCut() {
if (this.getScreenWidth < 480) {
return 1
} if (this.getScreenWidth < 576) {
return 2
} if (this.getScreenWidth < 768) {
return 3
} if (this.getScreenWidth < 992) {
return 4
}
return 6;
}
The concern arises from CodeMetrics' report indicating that the getCut() function has a complexity of 10, which is subpar. Any suggestions on how I can enhance this function?