JavaScript
Leaner if-statements

by Benny Neugebauer

const isnt_group_conversation = [z.conversation.ConversationType.CONNECT, z.conversation.ConversationType.ONE2ONE].includes(this.type());

if (isnt_group_conversation) {
  const has_name = this.participating_user_ets()[0] && this.participating_user_ets()[0].name;

  if (has_name) {
    return this.participating_user_ets()[0].name();
  }

  return '…';
}

if ([z.conversation.ConversationType.CONNECT, z.conversation.ConversationType.ONE2ONE].includes(this.type())) {
  if (this.participating_user_ets()[0] && this.participating_user_ets()[0].name) {
    return this.participating_user_ets()[0].name();
  }

  return '…';
}

Why half way?! you should add the second condition in a const as well! (in the variant A)

Lipis

Good catch! I edited it. :)

Benny Neugebauer

Sign in to comment!