Shabinder Singh
09/02/2020, 3:58 PMTwoClocks
09/02/2020, 6:08 PMTwoClocks
09/02/2020, 6:08 PMTwoClocks
09/02/2020, 8:00 PMTwoClocks
09/02/2020, 8:09 PMXuc Xiem
09/03/2020, 12:50 PMval lrgFac = b.fold(Int.MAX_VALUE) {acc,i-> Math.min(acc,i)}
some form of the Array.minXXX
method? And val maxA = a.reduce { acc, i -> Math.max(acc,i)}
is some form of Array.maxXXX
?
IMO, the findNumbers
function still refers to lrgFac
and b
outside of that function which makes it a little bit difficult to read.
Thank you very much for sharing your code. I learned a lot from it.TwoClocks
09/03/2020, 5:29 PMtailrec fun()
instead of while loops. If you think about it like that it becomes easier to read. Yeah, it's using var/val's out side the function, like a while()
loop would.TwoClocks
09/03/2020, 5:48 PMwhile()
loop means using a var. w/ tailrec
everything is all val. Also the tailrec
tells the compiler more about what's happening. In combo w/ only vals, in theory the compiler should be better able to optomize the loop (or at the least not have to check for normal while() for() edge cases). But I've never actually tested to see if that's true. The one times I did look the compiled byte code was very similar. So mostly that's just a story I tell myself 🙂
But I do like it better aesthetically. having no vars makes me happy for some reason.