Skip to content

Instantly share code, notes, and snippets.

@rosiecakes
Created October 7, 2016 15:54
Show Gist options
  • Save rosiecakes/ce5e57816c5b3bcf5453ae0f52b22bba to your computer and use it in GitHub Desktop.
Save rosiecakes/ce5e57816c5b3bcf5453ae0f52b22bba to your computer and use it in GitHub Desktop.
function multiplyByThree(array) {
var multiplier = 3;
// Handle undefined or null inputs
if (!array) {
throw new Error("Argument is undefined or null");
}
// Handle non-array inputs
if (!Array.isArray(array)) {
throw new Error("Argument is not an array");
}
var result = [];
for (var i = 0; i < array.length; i++) {
if (typeof array[i] !== "number") {
throw new Error("Array must contain valid integers only");
} else {
result[i] = array[i] * multiplier;
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment