question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extend array_position function with instance number

See original GitHub issue

Currently array_position only returns the first occurrence of the given element. We want to extend array_position to take an additional parameter instance similar to strpos.

array_position(x, element, instance) -> bigint

For example, for array x: [1, 3, 2, 1, 4, 3, 2, 5, 4, 1]:

array_position(x, 1) = 1 -- existing function
array_position(x, 1, 1) = 1 -- same as existing function with 2 input parameters
array_position(x, 1, 2) = 4 -- returns index of the second occurrence of 1
array_position(x, 5, 2) = 0 -- returns 0 because there is no second occurrence of 5
array_position(x, 1, -1) = 10 -- returns index of the first occurrence of 1 from the back
array_posision(x, 1, -2) = 4 -- returns index of the second occurrence of 1 from the back

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
adacocommented, Jan 10, 2020

@rongrong thanks! That does the trick.

1reaction
rongrongcommented, Jan 10, 2020

I use java 1.8. Try export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) and see whether it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ways to extend Array object in javascript - Stack Overflow
in 3rd way i want to extend the Array object internally Array3 class. How to do this so not to get "push is...
Read more >
5. Working with Arrays and Loops - JavaScript Cookbook [Book]
In Example 5-2, an array is created with several elements, including multiple instances of a specific value. The splice method is then used...
Read more >
Array Functions and Operators — Presto 0.278 Documentation
The [] operator is used to access an element of an array and is indexed starting ... the position of the instance -th...
Read more >
Array - JavaScript - MDN Web Docs
Returns true if the argument is an array, or false otherwise. Creates a new Array instance with a variable number of arguments, regardless...
Read more >
Array methods - The Modern JavaScript Tutorial
arr.forEach(function(item, index, array) { // ... do something with item });. For instance, this shows each element of the array:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found