Function function = new Function()

all programmers now crying at that edit summary
(added tryCreatePixelReturn, a hybrid of tryCreatePixel and createPixelReturn)
This commit is contained in:
Laetitia (O-01-67) 2023-03-05 13:20:07 -05:00 committed by GitHub
parent a735b3577e
commit 6ebb268e85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 0 deletions

View File

@ -1226,6 +1226,32 @@
};
};
function tryCreatePixelReturn(elementInput,x,y) {
//array handling
if(elementInput.includes(",")) { //CSTA
elementInput = elementInput.split(",");
};
if(Array.isArray(elementInput)) { //if element list
elementInput = elementInput.filter(function(e) {
return elementExists(e);
});
if(elementInput.length === 0) { throw new Error("elementInput has no existing elements") };
elementInput = randomChoice(elementInput);
};
//existence check
if(!elementExists(elementInput)) {
throw new Error("Element " + elementInput + " doesn't exist!");
};
//actual creation check
if(isEmpty(x,y)) {
return createPixelReturn(elementInput,x,y);
} else {
return false;
};
};
function createPixelReturn(element,x,y) { //sugar
var newPixel = new Pixel(x, y, element);
currentPixels.push(newPixel);