Last active
November 10, 2017 19:41
-
-
Save menduz/ef370473ecec2f1f2c6a71b1632ee88e to your computer and use it in GitHub Desktop.
FindIndex in DataWeave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun indexOf<T>(array: Array<T>, elem: T, carry: Number = 0): Number = | |
array match { | |
case [] -> -1 | |
case [head ~ tail] -> | |
if(head == elem) | |
carry | |
else | |
findIndex(tail, elem, carry + 1) | |
} | |
var HelloWorld = "Hello World!" splitBy '' | |
--- | |
HelloWorld findIndex 'H' // 0 | |
HelloWorld findIndex 'o' // 4 | |
HelloWorld findIndex 'aaaaa' // -1 |
leansh
commented
Nov 10, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment