TypeScript
Return mapped array without undefined values

by Benny Neugebauer

public get_serialized_standard_prekeys(): Promise<Array<any>> {
  const standardPreKeys: Array<{id: number; key: string}> = this.cachedPreKeys
    .map((preKey: Proteus.keys.PreKey) => {
      const isLastResortPreKey = preKey.key_id === Proteus.keys.PreKey.MAX_PREKEY_ID;
      return isLastResortPreKey ? undefined : this.serialize_prekey(preKey);
    })
    .filter(preKeyJson => preKeyJson);

  return Promise.resolve(standardPreKeys);
}

public get_serialized_standard_prekeys(): Promise<Array<any>> {
  const standardPreKeys: Array<{id: number; key: string}> = this.cachedPreKeys.filter((preKey: Proteus.keys.PreKey) => {
    const isLastResortPreKey = preKey.key_id === Proteus.keys.PreKey.MAX_PREKEY_ID;
    return isLastResortPreKey ? false : true;
  })
  .map((preKey: Proteus.keys.PreKey) => (this.serialize_prekey(preKey)));

  return Promise.resolve(standardPreKeys);
}