0

slicing and dicing of an array

How can one 'slice' an array from a specified item to the last item?

The 'end' parameter can be a negative number to count from the last item. So slice(array,1,-1) would return from the second item to the last but 1 item, IOW chopping off the first and last item. But how could one extract a range to the actual last item?

I realise one can use count(array) to get the length, but is there not a simpler way to set 'end' as the last item, in the same way as one can use a negative number to set the last but 1, or last but 2 etc?

2 replies

null
    • John_Halls
    • 2 yrs ago
    • Reported - view

    Hi

    I can't see an alternative to using the count() function.

     

    The construct will be

     

    let a := array

    let b := slice(a,5,count(a))

     

    Is using -1, -2 as a value for 'end' a documented feature? I'd be wary of that if not.

     

    Regards John

    • UKenGB
    • 2 yrs ago
    • Reported - view

    Using negatives to mean from the end of the array is pretty standard terminology in many languages, so it was natural to try it. However as you say, it is not documented, but that doesn't mean anything in the land of Ninox.

     

    I added a dummy item to the end of the array and then used -1 which works perfectly. I might have used count(), but in the end used the negative index. I can easily change it if required. In any case, it rather illustrates the incomplete nature of Ninox's array handling functionality.

Content aside

  • 2 yrs agoLast active
  • 2Replies
  • 245Views