Posts

Showing posts with the label parameter-passing

How to pass functions as parameters of another function with pre-specified arguments in python? [duplicate]

How to pass functions as parameters of another function with pre-specified arguments in python? [duplicate] This question already has an answer here: Is there a way to pass function with arguments that looks clean? For example, if I want pass function h with particular parameter-values a b from ars so that ars1 runs with these particular a b , what should I do? I want to do h a b a b def h(x, a, b): return x * a * b def ars(fcn): a = 1 b = 2 return ars1(fcn( . , a,b)) def ars1(fcn): return fcn(1)*fcn(1) ars(h) I could do def h(x, a, b): return x * a * b def ars(fcn): a = 1 b = 2 return ars1(fcn, a, b) def ars1(fcn, a, b): return fcn(1, a, b)*fcn(1, a, b) which achieves the purpose but since a b have nothing to do with ars1 , the code looks messy and lacks modularity. a b ars1 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. ...

How to run a function with optional argument/parameter in Google Apps Script

How to run a function with optional argument/parameter in Google Apps Script I am trying to run a function which has an optional argument/parameter in Google Apps Script. The function will create a Google Document and will also create a Google Slide if the user selects Yes. My problem is when the extractReplace function is being called, an error will occur because the copySlide is not defined. Here's how I'm calling the function: var copyId = DriveApp.getFileById(documentTemplate) .makeCopy(documentName + folderName, nsdestinationFolder) .getId(); var copyDocument = DocumentApp.openById(copyId); var copyBody = copyDocument.getActiveSection(); //call function to create technical slide proposal if(createTemplate == "Yes"){ createSlideProposal(); } else{ extractReplace(copyBody, copySlide = 0); } I have tried copySlide = 0, false, null, but it did not work as the copySlide is not defined when is passes to the copySlide.replaceAllText ...