function exampleFunction(){
var theVariable = "Lol!";
var variable2 = Lol.toLowerCase();
console.log(theVariable);
delete theVariable; //to prevent bugs, I want to ensure that this variable is never used from this point onward.
console.log(theVariable); //This still prints "Lol!", even though I just tried to delete the variable.
}
Run Code Online (Sandbox Code Playgroud)
在JavaScript中,是否可以防止变量在某个点之后在函数中使用?我已经尝试声明一个名为的字符串theVariable,然后我尝试使用删除变量delete theVariable,但即使在那之后console.log(theVariable)仍然打印出来theVariable的值.
我试着使用delete theVariable,使theVariable从该点以后不可用(为了防止自己不小心使用时不再需要它的变量),但它不会出现有这种效果.有没有办法解决这个限制?
我一直在尝试将RGB值的整数数组转换为PNG图像.如何从以下整数数组生成以下图像?

'''This is a 3D integer array. Each 1D array inside this array is an RGBA value'''
'''Now how can I convert this RGB array to the PNG image shown above?'''
rgbArray = [
[[255,0,0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0,0,255], [0,0,255], [0,0,255], [0,0,255]],
[[255,0,0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0,0,255], [0,0,255], [0,0,255], [0,0,255]],
[[255,0,0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0,0,255], [0,0,255], [0,0,255], [0,0,255]],
[[255,0,0], [255, 0, 0], …Run Code Online (Sandbox Code Playgroud) 我已经编写了一个Python库,该库在其函数调用中使用了很多命名参数,我想知道是否有任何方法可以自动删除所有这些命名参数,而不是手动删除(这是非常繁琐的任务) 。
例如,可以翻译此函数调用:
getClass(lang="Java", body=[
mainMethod(lang="Java", body=[
println(lang="Java", toPrint="Hello World")
])
])
Run Code Online (Sandbox Code Playgroud)
放入下面的函数调用中(它省略了命名参数,并且更加简洁?):
getClass("Java", [
mainMethod("Java", [
println("Java", "Hello World!")
])
])
Run Code Online (Sandbox Code Playgroud)
为此,一种可能的方法是编写一个将其自身的函数调用打印为字符串的函数-但是,我认为不可能编写执行此操作的函数。是否还有其他方法可以解决此问题?
在这里,我尝试创建一个匹配一个特定字符串的正则表达式:
#This is the string that the regex is intended to match
theString = "..!-+!)|(!+-!.."
print(re.compile(theString).match(theString))
Run Code Online (Sandbox Code Playgroud)
这会产生错误而不是匹配字符串:
raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis
Run Code Online (Sandbox Code Playgroud)
有没有办法生成一个只匹配一个特定字符串的正则表达式,比如这个?
我已经定义了一个名为函数initials内部的函数person,但我无法弄清楚如何在initials外面调用person:
main =
--I attempted to print the output of the initials function here.
(putStrLn ((person "firstName" "lastName") . initials)) --Not in scope: `initials'
--If this function call worked correctly, the output would be "f.l.".
person firstName lastName =
firstName ++ ["."] ++ lastName
where
fullName = firstName ++ " " ++ lastName
firstInitial = firstName !! 0
lastInitial = lastName !! 0
initials = [firstInitial] ++ "." ++ [lastInitial] ++ "." …Run Code Online (Sandbox Code Playgroud) 我正在使用HTML和JavaScript 编写一个"auto-wikifier"工具.对于要被文本化的文本中的每个单词,我需要获得包含该单词的页面列表(以便文本中的匹配短语可以被自动获取,如果找到它们).有没有办法使用维基百科的API或Web服务之一获取包含特定单词的所有维基百科页面的列表?
function getMatchingPageTitles(theString){
//get a list of all matching page titles for a specific string, using one of Wikipedia's APIs or web services
}
Run Code Online (Sandbox Code Playgroud) 是否可以在Java或Javascript中使用带有正则表达式的命名参数作为参数的名称?我希望能够调用这样的函数:
f("function name:", "drawCircle", "radius:" 1, "xPos:" 0, "yPos:", 0, "color:", "red");
Run Code Online (Sandbox Code Playgroud)
或者像这样,具有完全相同的效果:
f("name of function:", "draw a circle", "y position:", 0, "color:", "red", "rad:" 1, "x location:" 0);
Run Code Online (Sandbox Code Playgroud)
这两个都应该等于foo(1,0,0,红色).
在这两种情况下,给出的参数应该与正则表达式列表匹配.应该可以以任何顺序列出具有相同结果的参数和函数名称.
有没有办法实现这样的东西?
在Java中,如何划分两个不同的字符串,并将两个字符串的商作为字符串返回?
这是我正在尝试实现的功能:
public static String divideTwoStrings(string1, string2){
//this function should convert both strings to doubles,
//and then return their quotient as a string
}
Run Code Online (Sandbox Code Playgroud) 我正在研究一种源到源编译器,旨在翻译不同编程语言之间的程序.现在,我正试图找到一种方法来跟踪不同编程语言中的等效函数,这样我就可以找出一种语言中的哪个函数等同于另一种语言中的相同函数.
给定一个像这样的数组,是否有可能编写一个函数,它将以另一种语言返回相应的函数(例如,使用查询,例如print(getCorrespondingValue("Python", [["Java", "System.out.println"]])),它将返回Python中与System.out.printlnJava 相对应的函数)?
correspondingFunctionDatabase = [
[
["Java", "System.out.println"], ["JavaScript", "console.log"], ["Python", "print"],
],
[
["Java", "s1.replaceAll(str1, str2);"], ["JavaScript", "str.replace(str1, str2)"], ["Python", "str.replace(str1, str2)"], ["Haxe", "replace(str, str1, str2)"]
],
[
["JavaScript", "str.split(separator)"], ["Java", "str.split(separator)"], ["Python", "re.split(separator, string)"]
],
[
["JavaScript", "eval(statement)"], ["Python", "eval(statement)"]
]
]
Run Code Online (Sandbox Code Playgroud)