{"ScriptPreparationCode":"function anas(array, arraysCount) {\r\n\r\n\tlet arrayLength = array.length;\r\n\r\n\tif( arrayLength == 0 ) {\r\n \treturn array;\r\n }\r\n \r\n if( arraysCount \u003E arrayLength ) {\r\n \treturn array;\r\n }\r\n \r\n let result = [];\r\n let newArray = [];\r\n \r\n\tconst newArraysLength = arrayLength % arraysCount == 0 ? Math.floor( arrayLength / arraysCount) : Math.ceil ( arrayLength / arraysCount);\r\n \r\n // We loop \r\n for( let i = 0 ; i \u003C arrayLength; i\u002B\u002B ) {\r\n if( i % newArraysLength == 0 ) {\r\n \tif( i \u003E 0 ) {\r\n \tresult.push( newArray );\r\n newArray = [];\r\n }\r\n }\r\n \r\n newArray.push( array[i] );\r\n }\r\n \r\n let canBeSplitEqually = ( ( arrayLength ) % newArraysLength == 0 );\r\n console.log(\u0022canBeSplitEqually = \u0022, canBeSplitEqually);\r\n \r\n if( !( canBeSplitEqually ) ) {\r\n \tresult.push( newArray );\r\n }\r\n\r\n\treturn result;\r\n}\r\n\r\nfunction nabil (\r\n array,\r\n n\r\n) {\r\n\r\n const elementsPerGroup = Math.round(array.length / n);\r\n let result = [];\r\n let positionIndex = 0;\r\n for (let i = 1; n \u003E= i; i\u002B\u002B) {\r\n const lastIndex =\r\n i === n\r\n ? array.length - positionIndex \u002B positionIndex\r\n : elementsPerGroup \u002B positionIndex;\r\n result.push(array.slice(positionIndex, lastIndex));\r\n positionIndex = positionIndex \u002B elementsPerGroup;\r\n }\r\n return result;\r\n}; \r\n\r\n","TestCases":[{"Name":"Anas","Code":"anas([1, 2, 3, 4, 5], 3)\r\n","IsDeferred":false},{"Name":"Nabil","Code":"nabil([1, 2, 3, 4, 5], 3)","IsDeferred":false}]}