вынесена функция для разбиения по строкам

This commit is contained in:
ekallin 2024-01-07 19:47:53 +04:00 committed by ns.potapov
parent 29d06985cc
commit f642529571
3 changed files with 11 additions and 15 deletions

1
.gitignore vendored
View File

@ -23,3 +23,4 @@ dist-ssr
*.sln
*.sw?
node_modules
*.env

View File

@ -0,0 +1,7 @@
export function splitByRows(array, countInRow) {
let subarray = []; //массив в который будет выведен результат.
for (let i = 0; i < Math.ceil(array.length / countInRow); i++) {
subarray[i] = array.slice(i * countInRow, i * countInRow + countInRow);
}
return subarray;
}

View File

@ -4,7 +4,7 @@ import useMovies from '../components/movies/hooks/MoviesHook';
import RowCategories from '../components/RowCategories/RowCategories';
import useCategories from '../components/categories/hooks/CategoriesHook';
import RowFilms from '../components/RowFilms/RowFilms';
import { splitByRows } from '../components/utils/funcs';
const Catalog = () => {
@ -16,13 +16,7 @@ const Catalog = () => {
if (currentFilter == "") {
let size = 3; //размер подмассива
let subarray = []; //массив в который будет выведен результат.
for (let i = 0; i < Math.ceil(categories.length / size); i++) {
subarray[i] = categories.slice((i * size), (i * size) + size);
}
let categoriesByRow = subarray;
const categoriesByRow = splitByRows(categories, 3);
return (
<>
@ -37,13 +31,7 @@ const Catalog = () => {
);
}
let size = 3; //размер подмассива
let subarray = []; //массив в который будет выведен результат.
for (let i = 0; i < Math.ceil(movies.length / size); i++) {
subarray[i] = movies.slice((i * size), (i * size) + size);
}
let moviesByRow = subarray;
const moviesByRow = splitByRows(movies, 3);
return (
<>