Subscribe Bookmark RSS Feed

Step function

schniggeldorf

Community Trekker

Joined:

Jun 23, 2011

The following jsl code:

i=97;
print(i,Step( i, 20, "error1", 95, "M03", 125, "error2", 185, "M06", 215, "error3", 370, "M12", 400, "error4" ));

produces:
97
"error1"

as output in the log.

Shouldn't it produce:
97
"M03"

instead, since 95 is the greatest x in the list that is <= 97?

Can anybody advise what I'm doing wrong?

Thanks.
2 REPLIES
mattf

Community Trekker

Joined:

Jun 23, 2011

Hi:

I believe that is just of question of interpretation - kind of like a flexible floor() function with a list:

It is correct - returning:
(95) is the greatest x value in the list that is less than or equal to the x (97) specified as the first argument.

Best,
-Matt

mpb

Super User

Joined:

Jun 23, 2011

It appears that the Y array needs to be numeric. To get the effect you are looking for this example may be useful:

i = 97;
stepi = Match( Step( i, 20, 20, 95, 95, 125, 125 ),
20, "twenty",
95, "ninety five",
125, "hundred twenty five"
);
Show( i, stepi );