Javascript for loop not appending list in dictionary -
and i'm not sure understand problem @ all.
var vtf=[]; // dictionary maps number-> list var length; var s; // list of numbers s.length = length // length , s set values for(i=0; i<length; i++) { var f=s[i]; if(f in vtf) vtf[f].push(i); else vtf[f]=[i]; }
so check if vtf contains value f=s[i]. if appends list contained @ vtf[f] , if doesn't makes new list element.
the problem after running every index of vtf contains first added despite me knowing every value saved in vtf should have list of multiple elements.
i can't understand i'm doing wrong. when put alerts inside if statement don't pop when put them outside loop, same value, show it's evaluating true number of times.
Comments
Post a Comment