Tuesday, 21 March 2017

CodeWars - Is Ruby Coming?

Is Ruby Coming?

Not a lot to say about this one.

function isRubyComing(list) {  
  return list.filter(obj => obj.language === 'Ruby').length > 0;
}

I was trying to find a less hokey way of asserting the return boolean, but all my efforts at double-negating the function statement failed because an empty array is still a truthy value.

Only on completion did I see what I was looking for in other people’s solutions array.some()

function isRubyComing(list) {
  return list.some(obj => obj.language === 'Ruby');
}

Nice and declarative. I love it.