Scala: searching array element using recursion


Below is an example of searching of elements in an array using scala monomorphic function as well recursion

object arraysearch extends App {

def searcharray(ss:Array[String],key:String):Int=
def loop(n:Int):Int=
if(ss(n)==key) n //
else if (n<=0) -1
else loop(n-1)
loop(ss.length-1)  // pass the arary(length -1) in loop function  recursion



Thanks please comment and follow


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s