Skip to content

Instantly share code, notes, and snippets.

@delonnewman
Last active August 17, 2023 02:35
Show Gist options
  • Save delonnewman/d0cf0d30c818cccfc65ced8ac945df4b to your computer and use it in GitHub Desktop.
Save delonnewman/d0cf0d30c818cccfc65ced8ac945df4b to your computer and use it in GitHub Desktop.
elisa
function return1StepArray(num1, num2, step) {
let myArray = [];
//Edge Cases
//Check if there are three values:
if (!num1 || !num2 || !step) {
return "Input three numbers.";
}
//Receive only numbers
if (
typeof num1 !== "number" ||
typeof num2 !== "number" ||
typeof step !== "number"
) {
return "Error, use only numbers";
}
//Round numbers down
num1 = Math.floor(num1);
num2 = Math.floor(num2);
step = Math.floor(step);
//Receive only numbers in ascending order
if (num1 >= num2) {
return "Error! numbers are not in ascending order";
}
for (let i = num1; i <= num2; i += step) {
myArray.push(i);
}
return myArray;
}
console.log(return1StepArray(2, 10, 2));
function sumNumbers(arr) {
let temp = 0;
let ok = true;
for (let i = 0; i <= arr.length - 1; i++) {
if (typeof arr[i] != "number") {
ok = false;
break;
} else {
temp += arr[i];
}
}
if (ok == false) {
return "Error";
} else {
return temp;
}
}
console.log(sumNumbers([1, 2, 3, "4", 5]) + 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment