Creating two arrays from variable in javascript -


in function, variable midarc stores positive , negative numbers. how can these values used create 2 new arrays, 1 containing positive values , 1 containing negative values?

function cosval(){     var val = [2,5,7,6,9];     for(i=0; i<val.length; i++){         var midarc = math.cos(val[i]);         alert(midarc); //displays 3 positive , 2 negative numbers      }    } 

just check whether or not number greater or less zero:

function cosval(){     var val = [2,5,7,6,9], positives = [], negatives = [];     for(i=0; i<val.length; i++){         var midarc = math.cos(val[i]);         (midarc >= 0) ? positives.push(midarc) : negatives.push(midarc);     }    } 

Comments

Popular posts from this blog

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

c++ - qgraphicsview horizontal scrolling always has a vertical delta -