coffeescript - How to work with copy of an array and reset it later -


i have array list predefined data want work on.

then want make copy of array on work, i.e. shuffling , popping 1 element. after list empty, want reset it, i.e. fill again contents of list.

what have this:

list = [{...}, {...}, {...}] list2 = list  shuffle = (a) ->   = a.length   while --i > 0     j = ~~(math.random() * (i + 1))     t = a[j]     a[j] = a[i]     a[i] = t    get_list_item = ->   shuffle(list2)   list2.pop()  reset_list = ->   list2 = list 

but after i've popped items list2, reset_list() doesn't reset list. it's still empty

list2 = list doesn't make copy of list, creates pointer same array. when using pop() original (and only) array loses elements.

replace these instructions list2 = list.slice 0 , should work want to.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -