 R.pipe to 


*

*Group the objects by temp's value, 

*Convert the object of groups to an array of pairs

*Reduce the pairs to the one with the max key (the temp)

*return the value from the pair




const { pipe, groupBy, prop, toPairs, reduce, maxBy, head, last } = R;

const regions = [
  {name: 'california', temp: 30},
  {name: 'alabama', temp: 20},
  {name: 'newyork', temp: 30}
];

const result = pipe(
  groupBy(prop('temp')),
  toPairs,
  reduce(maxBy(pipe(head, Number)), [-Infinity]),
  last
)(regions);

console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>



A: Another Ramda approach:


const {reduce, append} = R

const regions = [{name:'asd', temp: 13},{name: 'fdg', temp: 30}, {name: 'asdsd', temp: 30}]

const maxTemps = reduce(
  (tops, curr) => curr.temp > tops[0].temp? [curr] : curr.temp === tops[0].temp? append(curr, tops) : tops,
  [{temp: -Infinity}]
)

console.log(maxTemps(regions))
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>


This version only iterates the list once.  But it's a bit ugly.
I would usually prefer the version from Ori Drori unless testing shows that the performance is a problem in my application.  Even with the fix from my comment, I think that code is easier to understand than this one.  (That wouldn't be true if there were only two cases.  (< versus >= for instance.)  But when there are three, this gets hard to read, however we might format it.
But if performance is really a major issue, then your original code is probably faster than this one too.

A: A different approach to this (albeit a little more verbose) is to create some helpers to generically take care of folding over a list of things to extract the list of maximums.
We can do this by defining a Semigroup wrapper class (could also be a plain function instead of a class).
const MaxManyBy = fn => class MaxMany {
  constructor(values) {
    this.values = values
  }
  concat(other) {
    const otherValue = fn(other.values[0]),
          thisValue  = fn(this.values[0])

    return otherValue > thisValue? other
         : otherValue < thisValue? this
         : new MaxMany(this.values.concat(other.values))
  }
  static of(x) {
    return new MaxMany([x])
  }
}

The main purpose of this class is to be able to combine two lists by comparing the values contained within, with the invariant that each list contains the same comparable values.
We now can introduce a new helper function which applies some function to each value of a list and then combines them all using concat.
const foldMap = (fn, [x,...xs]) =>
  xs.reduce((acc, next) => acc.concat(fn(next)), fn(x))

With these helpers, we can now create a function that pulls the maximum temperatures from your example.
const maxTemps = xs =>
  foldMap(MaxManyBy(({temp}) => temp).of, xs).values

maxTemps([
  {name: 'california', temp: 30},
  {name: 'alabama', temp: 20},
  {name: 'newyork', temp: 30}
])
//=> [{"name": "california", "temp": 30}, {"name": "newyork", "temp": 30}]

There is an assumption here that the list being passed to foldMap is non-empty. If there's a chance that you'll encounter an empty list then you will need to modify accordingly to return a default value of some kind (or wrap it in a Maybe type if no sane default exists).
See the complete snippet below.


const MaxManyBy = fn => class MaxMany {
  constructor(values) {
    this.values = values
  }
  concat(other) {
    const otherValue = fn(other.values[0]),
          thisValue  = fn(this.values[0])

    return otherValue > thisValue? other
         : otherValue < thisValue? this
         : new MaxMany(this.values.concat(other.values))
  }
  static of(x) {
    return new MaxMany([x])
  }
}

const foldMap = (fn, [x,...xs]) =>
  xs.reduce((acc, next) => acc.concat(fn(next)), fn(x))

const maxTemps = xs =>
  foldMap(MaxManyBy(({temp}) => temp).of, xs).values

const regions = [
  {name: 'california', temp: 30},
  {name: 'alabama', temp: 20},
  {name: 'newyork', temp: 30}
]

console.log(maxTemps(regions))


balm
noun
Serverl fragrant balms.
- An example of a balm is aloe.
- An example of a balm is the aloe plant.
- An example of a balm is Chapstick.
The definition of a balm is a soothing, oily substance that smells good and comes from certain plants or is man-made.
balm
- an aromatic gum resin obtained from certain trees and plants (esp. genus Commiphora of the bursera family) and used in the manufacture of perfume, medicine, etc.; balsam
- any fragrant ointment or aromatic oil for healing or anointing
- anything healing or soothing, esp. to the mind or temper
- any of various aromatic plants of the mint family, as the lemon balm
- pleasant odor; fragrance
Origin of balmMiddle English baume ; from Old French basme ; from Classical Latin balsamum, balsam ; from Classical Greek balsamon ; from Semitic (cf. Classical Hebrew (language) basam, Arabic baš?m
balm
noun
- a. A chiefly Mediterranean perennial herb (Melissa officinalis) in the mint family, grown for its lemon-scented foliage, which is used as a seasoning or for tea. Also called lemon balm.b. Any of several related plants in the mint family, such as the bee balm and the horse balm.
- Any of various aromatic resins exuded from several trees and shrubs, especially the balm of Gilead (Commiphora) and related plants in the family Burseraceae.
- An aromatic salve or oil.
- A pleasing aromatic fragrance.
- A soothing, healing, or comforting agent or quality.
Origin of balmMiddle English baume, balsam, from Old French basme, from Latin balsamum; see balsam.
balm
Noun
(plural balms)
- Any of various aromatic resins exuded from certain plants, especially trees of the genus Commiphora of Africa, Arabia and India and Myroxylon of South America.
- A plant or tree yielding such substance.
- Any soothing oil or lotion, especially an aromatic one.
- There is a balm in Gilead.... (Spiritual)
- (figuratively) Something soothing.
- Classical music is a sweet balm for our sorrows.
- Any of various aromatic plants of the genus Melissa, such as lemon balm (Melissa officinalis) or bee balm.
Verb
(third-person singular simple present balms, present participle balming, simple past and past participle balmed)
Origin
From Anglo-Norman and Middle French baume, from Old French basme, from Latin balsamum. Spelling modified 16th c. to conform to Latin etymology.
SentencesSentence examplesThis model is a progression from a basic paper tessellation of a molecule. Unlike most tessellations, it is folded very slightly, without any overlapping. Its shape, being as far removed as possible from the classic rectangle, creates a mesmerizing vision of shifting squares, giving rise to its name. As an origami artist and designer, I love to find applications that exceed the potential of paper. This model is created by four diagonal lines that emerge from the central square. It could not be any simpler, and yet the effect is quite the opposite.It was a surprisingly emotional – and quite upbeat – Jeff Gordon celebrating an historic victory here Sunday, his 84th since joining the NASCAR tour 20-some years ago, tying him with Hall