Created
March 4, 2019 14:35
-
-
Save developer-sdk/807caf5022762ce094887341b3967876 to your computer and use it in GitHub Desktop.
scala index of
This file contains hidden or 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
| object FuncThinking1 extends App { | |
| def firstIndexOfAny(input: String, searchChars: Seq[Char]): Option[Int] = { | |
| def indexedInput = (0 until input.length).zip(input) | |
| val result = for (pair <- indexedInput; char <- searchChars; if (char == pair._2)) | |
| yield (pair._1) | |
| if (result.isEmpty) | |
| None | |
| else | |
| Some(result.head) | |
| } | |
| val result1 = firstIndexOfAny("123445asldkfjasdf", "a")) | |
| println(result1) | |
| def indexOfAny(input:String, searchChars:Seq[Char]):Seq[Int] = { | |
| def indexedinput = (0 until input.length).zip(input) | |
| for(pair <- indexedinput; char <- searchChars; if(char == pair._2)) | |
| yield pair._1 | |
| } | |
| val result2 = indexOfAny("123445asldkfjasdf", "35") | |
| println(result2) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment