JavaScript
Conditionally initialize an Array

by Benny Neugebauer

function init(ids, condition) {
  if (condition) {
    ids = [1, 2, 3];
  } else {
    ids = [1, 2];
  }
  
  return ids;
}

console.log(init([], true)); // [1, 2, 3]
console.log(init([], false)); // [1, 2]

function init(ids, condition) {
  if (condition) {
    ids = ids.concat([1, 2, 3]);
  } else {
    ids.push(1);
    ids.push(2);
  }

  return ids;
}

console.log(init([], true)); // [1, 2, 3]
console.log(init([], false)); // [1, 2]