Created
October 7, 2016 15:54
-
-
Save rosiecakes/ce5e57816c5b3bcf5453ae0f52b22bba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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