Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 10th, 2007, 1:52 AM   #1
littlejim4
Newbie
 
Join Date: Dec 2007
Location: South Wales
Posts: 4
Rep Power: 0 littlejim4 is on a distinguished road
Unhappy Returning Index

Hi all,

I have a bit of a problem with a project and was hoping that somebody could help me out. Here goes!

I have a set of integers ie (1,-2,0,4,-5,0,7,-8,0,10) what I need to do is loop through and then return only the positive integers leaving out the negatives. This is easy enough but I have to return the index positions of the positive integers ie, (1,3,4,6,7,9,10). However I'm having major trouble with the logic because I need the integers in reverse order. What I get is the index integers from 1-7 not waht I need.

Can anybody help me out with this one. Many thanks in advance.
littlejim4 is offline   Reply With Quote
Old Dec 10th, 2007, 3:07 AM   #2
hollystyles
Omlette du fromage
 
hollystyles's Avatar
 
Join Date: Oct 2007
Posts: 29
Rep Power: 0 hollystyles is on a distinguished road
Re: Returning Index

Just loop the array of integers in reverse.

var integerArray = [1,-2,0,4,-5,0,7,-8,0,10];
var positiveInts = [];
for(var i = integerArray.length - 1, i >= 0, --i)
{
     if(integerArray [i] >= 0)
        positiveInts[positiveInts.length] = integerArray[i];
}
hollystyles is offline   Reply With Quote
Old Dec 10th, 2007, 8:39 AM   #3
littlejim4
Newbie
 
Join Date: Dec 2007
Location: South Wales
Posts: 4
Rep Power: 0 littlejim4 is on a distinguished road
Re: Returning Index

Many thanks,

I was getting bogged down by the logic.
littlejim4 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Method not returning string csrocker101 C# 1 Apr 6th, 2007 6:45 PM
Returning An Array Of Characters Sane C++ 22 Aug 22nd, 2006 3:44 AM
Method not returning? titaniumdecoy Python 6 Jun 28th, 2006 2:19 PM
Index in a table gj15987 Delphi 12 Aug 22nd, 2005 7:02 PM
Finally returning.... Sebeq Community Introductions 12 Feb 23rd, 2005 11:33 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC