treehouse : what would you like to learn today?
Web Design Web Development iOS Development

How to detect an integer in a list of numbers

  • Hi,
    Wondering if anybody has ever solved this one. I see a couple of snippets that will tell if a number you put in is odd or even but none that will detect a whole number from the searches I made so far.

    Thanks in advance.

  • Can you give an example of what you'll be looking at?
  • Hi Doc,
    In a column of numbers like this, I want the 0,1,2,3,4,5,6,7,8 rows.
    Sometimes the program skips an integer so then I need to plug in a virtual.

    George
    0
    0.0833
    0.1667
    0.25
    0.3333
    0.4167
    0.5
    0.5833
    0.6667
    0.75
    0.7667
    1
    1.3333
    1.35
    2
    2.1
    2.15
    2.2
    2.25
    2.3
    2.4
    2.45
    2.5
    2.55
    2.65
    2.7
    2.75
    3
    3.05
    3.1
    3.15
    4
    4.9833
    5
    5.05
    5.1
    5.15
    5.2
    5.25
    5.35
    5.4
    5.45
    5.5
    5.55
    5.6
    5.7
    5.75
    6
    6.25
    6.3333
    6.4167
    6.5833
    6.6667
    6.75
    6.7667
    7.0833
    7.1667
    7.2
    7.25
    7.3333
    7.4167
    7.45
    7.5
    7.5833
    7.6667
    7.7
    7.75
    7.8333
    8
    8.0833
    8.1667
    8.25
    8.3333
    8.4167
    8.5
    8.5833
    8.6667
    8.75
  • Thanks Doc,

    I am seeing the same problem there that I am trying to solve.
    That snippet detects the change in the integer and prints it, ignoring the decimals after the " . " It gets the first integer but then on the
    next row the trouble starts.

    George
  • Hi George!

    What results are you expecting? Maybe I'm not understanding but what you mean by "on the next row the trouble starts". Do you want integers only? or the entire number? Are they supposed to be sorted into rows?
  • Hi Mottie,

    If you look at this http://jsfiddle.net/Jk5mA/ you will see what I am trying to separate. I only want whole numbers which means nothing past the decimal point out to the capacity of the program. The 1,2,3,
    etc, integers in the list are the ones to separate from the others. This list is a derivative from a time series list of seconds incrementing. I want to be able to find minutes and hours in that list. Sometimes, the seconds skip so there is another problem too. I will need to make a virtual whole number at the point it skips.

    Thanks for your interest and help

    George
  • Hmm, sounds like a pretty long list.

    So did you want to round the numbers or just truncate them?

    The result table will list as seconds? So how will you determine the number of minutes, hours, etc? will that be another column?

    What value will be set to the seconds that are skipped? If there are no values, then why not just count seconds from one to the highest number in the list?
  • Hi Mottie,

    You may have your finger on it. It is easy to add columns for minutes, hours, etc. What I am trying to do is to limit the number of BIN files.
    This may do the trick.

    Thanks,
    George
  • If I understand, you want only the rows that have a whole number in it, with no decimals? So if the list skips 3 you dont want to have 3 in the list?

    ie: 1, 1.5, 2, 2.3, 3.7, 4, 4.9, 5 would result in 1, 2, 4, 5, correct?

    you could take each number and round it and then compare to the original number to see if it is different, then if not add it to another list.


    a = numberlist[0];
    b = round(a);
    if (a==b) shortlist.push(a);



    something like that. Of course it would need to be in a loop.

    here is theDoc's jsfiddle(modified) http://jsfiddle.net/Jk5mA/1/
  • Hi Schmotty,

    Great idea! Works like a charm and saves many BIN files.

    George