1

Note: I'm very beginner in the whole programming concept and practices.

I've a function which outputs all the combinations of possible numbers. The number of output will be 10,260,432,000. So in my function rather than using the push function to array like this:

 result.push([].concat.apply([], [ xs[i], ys[j] ]));

I've to save the output somewhere else, may be in the csv or txt file. The full code is here . So how can I edit the function so that it would save the output to the file instead of memory. For now this function crash if I would to use 30 numbers in the original array.

It is also ok to save all those output array in database too.

user2906838
  • 1,178
  • 9
  • 20
  • 1
    What context? In the browser - use HTML5 local storage. In node.js, use file system operations. Something else? Not sure. – PaulProgrammer Aug 24 '15 at 17:42
  • possible duplicate of [Using HTML5/Javascript to generate and save a file](http://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file) – Serlite Aug 24 '15 at 17:43
  • that can be local storage, from which I can easily access the output, may be in csv file or something like that in which the output can be easily read. I really don't know how to handle this. – user2906838 Aug 24 '15 at 17:44
  • @Serlite, but how do I correlate my function with the function which saves the output as a file is also my problem. – user2906838 Aug 24 '15 at 17:48
  • see [Abacus](https://github.com/foo123/Abacus) which uses an iterator pattern to generate combinatorial objects (even if amount is large) (ps author) – Nikos M. Aug 24 '15 at 17:50
  • @user2906838 You could leverage the `Array.toString()` method, then create a data URI from the resultant string using `encodeURIComponent(arrayString)`, like one of the answers in the linked question. – Serlite Aug 24 '15 at 17:58
  • Side note: change that line of code to `result.push( [ xs[i], ys[j] ] );` Your code is: creating a new empty array to obtain a reference to the concat function, then creating another new empty array on which to apply the function, and creating a third new array containing two elements that will be concatenated with the empty array you made just prior which will result in the same array you just created. If that sounds confusing ... it is rather circuitous and uses more memory and CPU cycles than is useful. – dsh Aug 24 '15 at 17:58
  • @Nikos M, it might be the stupidest question, but how shall I use your solution for my need. I really didn't understand. I know I'm sounding stupidest here. – user2906838 Aug 24 '15 at 18:34
  • @user2906838, the comment implies using an iterator pattern to generate combinatorial objects (which may be quite large if generated at once). This is the point relevant to the question. The rest is an actual example of this of my own combinatorial library – Nikos M. Aug 25 '15 at 15:12
  • @user2906838, this is called "ranking and unranking" (in the context of combinatorics) and any desired combinatorial object can be indexed and generated on the fly (so this is relevant to the question which has to do with very large numbers of pre-computed combinatorial objects, as an alternative) – Nikos M. Aug 25 '15 at 15:15
  • @NikoM, I am really thankful toward you. Ok I'm trying to use your Abacus, but I need to find out the way as how can I integrate it. – user2906838 Aug 25 '15 at 19:39

0 Answers0