Javascript Arrays - Find Duplicates -


this question has answer here:

here question...

given array populated numbers function parameter, produce resulting array contains duplicates number array. example, given array [ 1, 2, 4, 4, 3, 3, 1, 5, 3 ] should return [1, 4, 3]. bonus points return sorted array.

i starting out javascript - know language however, using in correct way ( 1 should ) i'm still getting grips with.

my pseudo code to:

create array numbers above var numbers = [1, 2, 4, 4, 3, 3, 1, 5, 3];

then create empty array named "result" var result = [];

create loop goes through var numbers check duplicates populate empty array "result" duplicates

for (var = 0;i < numbers.length; i++) {  //this i'm stuck... } 

i'm not sure within loop populate var result , throw in mix... given array has function parameter makes sense can change numbers in 1 place.

any feedback on thought process on far appreciated wanting learn how achieve this.

here jsfiddle of progress far... http://jsfiddle.net/fbauw/

one way of doing (and it's not way) checking existing elements in array. take @ javascript's lastindexof function:

http://www.w3schools.com/jsref/jsref_lastindexof_array.asp

it return -1 if object not exist in array, , if exists, return index of later position in. can use if statement in loop checks whether or not there index containing number, , add in results array if , if index != index on (if equal, means there 1 of element in list).

if need more help, comment here , can type code in!

good luck!


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -