Last active
November 25, 2021 05:00
-
-
Save prio101/9dece1570dfed1c86f4db99a709c412e to your computer and use it in GitHub Desktop.
Group by the n spice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Idea: | |
// get the main result set into: | |
// three seperate list in a main list: [[1,2,3], [1,2], [1,2....,n]] | |
// Maybe here in this case js will not clone the main list . | |
// it will manipulate the main list. Attention to it. | |
list = [1,2,3,4,5,6,7,8,9] | |
const group_by_n = (list) => { | |
// same as before: | |
let temp_list = [] | |
let group_base_spice = 3 | |
let group_base_spice_special_case_secon_row = 2 | |
let result_list = [] | |
for(item in list){ | |
if(item == 0 && list.length > group_base_spice){ | |
temp_list = list.splice(0, group_base_spice); | |
result_list.push(temp_list); | |
temp_list = [] // reset | |
group_base_spice = group_base_spice_special_case_secon_row | |
} | |
if(item == 1 && list.length > group_base_spice){ | |
temp_list = list.splice(0, group_base_spice); | |
result_list.push(temp_list); | |
temp_list = [] | |
} | |
// guess this line will throw error | |
// before: result_list.append(list) | |
// after: only add the rest of item | |
result_list.push(list[item]) | |
console.log("this should show three seperate list:",result_list) | |
return result_list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result should be = [[1,2,3], [4,5], [rest....n]]
now run a loop on the view file to get the sets as grouped.
like: while 1 -> 2 do this.
for row 3 just print rest or paginate .