defclosestNumber(x:Int,y:Int,givenNumber:Int):Int={if(abs(givenNumber-x)>abs(givenNumber-y)){y}else{x}}valgivenNumber=900valnums=List(100,200,400,800,1600,3200,6400,128000)println(nums.reduce((x,y)=>closestNumber(x,y,givenNumber)))//==> Prints 800
Thanks for the challenge!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey! Let's do it the Scala way:
Thanks for the challenge!