0 Replies - 352 Views - Last Post: 21 August 2017 - 02:40 AM

#1 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4128
  • View blog
  • Posts: 13,020
  • Joined: 08-June 10

functional equivalent of if()

Posted 21 August 2017 - 02:40 AM

Hello,

I have a list that is filtered for a certain condition and if that list doesn't contain more than one result another function should be applied. With imperative programming that is done using if() but I'd like to know if that's also possible with functional programming.

// imperative
$candidates = $('select').find('option').filter(/* ... */);

if ($candidates.length === 1) { // would work equally well with `< 2`
    $candidates.prop('selected', true);
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1