1

Firstly, good morning.

PreludeLS is able to get the minimum value of an array:

[1 2 3 4 5 6 7 8 9 10] |> minimum #=> 1

Now I figure out a way to get the minimum-by a unknown key. Let's suppose I have an object called A and it has 3 properties with 3 float values:

A =
  A: 3.2
  B: 4.2
  C: 4.7

And I want to return the KeyValuePair of the element with a lower value:

{A: 32}

I can get the minimum by several objects by these objects having an equal index. How can I get the minimum by a unknown key?

  • Yeah, I've already read 3 times LiveScript's documentation and 2 times PreludeLS documentation
Marcelo Camargo
  • 2,240
  • 2
  • 22
  • 51
  • 2
    Using only prelude-ls functions: `A |> obj-to-pairs >> (minimum-by (.1)) >> (->[it]) >> pairs-to-obj` you can write it better if you define an `Obj.fold` for your case. – homam Oct 20 '14 at 20:48

1 Answers1

2
A |> obj-to-pairs |> minimum-by (.1)
#=> ['A', 3.2]

A |> obj-to-pairs |> minimum-by (.1) |> -> {(it.0): it.1}
#=> {A: 3.2}
Oleh Prypin
  • 33,184
  • 10
  • 89
  • 99