我正在阅读FP,我有两个基本问题:
FP表示功能应该采用一个输入并提供单个输出.那我该怎么做void方法呢?它没有任何回报吗?
FP说功能应该有单一的责任,那么我们如何处理log方法内的语句呢?那不违反规定吗?
希望知道他们如何在斯卡拉,哈斯克尔处理这些事情.提前致谢.
编译以下代码失败:
public static void swap(List<?> list, int i, int j) {
list.set(i, list.set(j, list.get(i)));
}
Run Code Online (Sandbox Code Playgroud)
喜欢:
Swap.java:5: set(int,capture#282 of ?) in List<capture#282 of ?> cannot be applied to (int,Object)
list.set(i, list.set(j, list.get(i)));
Run Code Online (Sandbox Code Playgroud)
但如果我这样做:
public static void swap(List<?> list, int i, int j) {
swapHelper(list, i, j);
}
private static <E> void swapHelper(List<E> list, int i, int j) { list.set(i, list.set(j, list.get(i)));
}
Run Code Online (Sandbox Code Playgroud)
它的工作完美.
但我在这里有一个基本的疑问.仿制药据说是不变的,所以List<String>不是亚型List<Object>,对吧?
如果是这样,那么如何在上面的方法中,我们能够传递List<?>给List<E>?这是怎么回事?
我很新的D3,这是我做了什么至今这里.
实际代码在这里:
var width = 1840,
height = 1480,
constant = 100,
color = "#BCD8CD"
var nodes = [
{label: '1st stage', x: constant, y: 215 , width:70,height:50 , color :color , stage: true },
{label: '2nd stage', x: constant + 150 , y: 215 ,width:70,height:50 ,color :color, stage: true },
{label: '3rd stage', x: constant + 279, y: 215 ,width:70,height:50, color :color, stage: false },
{label: '4th stage', x: constant + 460, y: 215 ,width:70,height:50, color :color, …Run Code Online (Sandbox Code Playgroud) 在hyperapp代码库中,我们能够看到这一行:
https://github.com/hyperapp/hyperapp/blob/master/src/app.js#L135
这表现了:
try {
element[name] = value
} catch (_) {}
Run Code Online (Sandbox Code Playgroud)
显然,element是一个HTMLElement,value是一个功能!这里有趣的部分是,如果name说是例如onclick并且value是一个向控制台输出内容的函数,上面的代码正确地添加了事件监听器onclick.
我想知道这是否是一个简短的手addEventListener或我错在这里?
我有一个面试问题是:
"将给定的字符串转换为回文,只要输出(回文字符串)应包含给定字符串的子字符串"
所以我这样做,root作为输入,我将找到该字符串的反向并将其附加到给定的输入.所以我得到了字符串:
roottoor
Run Code Online (Sandbox Code Playgroud)
这是一个回文并且还包含i/p(root)存在于o/p中.
根据解决方案,该管理人员表示,它不是最佳解决方案,您能给出最佳解决方案吗?
我无法找到除此之外的任何东西.
还有其他方法吗?
他说需要用Java完成.
我正在使用 q 承诺,并且我想在承诺开始时向旋转器显示。目前我正在这样做:
getPromise().then(function() { spinner.hide() })
Run Code Online (Sandbox Code Playgroud)
在getPromise()fn 中,我显示了微调器,所以getPromise看起来像:
function getPromise()
{
spinner.show()
}
Run Code Online (Sandbox Code Playgroud)
但是有什么方法可以拦截thenq 中的块,以便我可以将 the 添加spinner.show到该拦截中?
在es6中,以下似乎是有效的代码:
function test(a1,{a=1,b=2} = {},) {}
Run Code Online (Sandbox Code Playgroud)
注意,功能args中的额外功能.我不确定这是否是一个错误,因为这个额外,只被接受用于解构分配.
javascript ×4
java ×2
algorithm ×1
d3.js ×1
function ×1
generics ×1
haskell ×1
optimization ×1
palindrome ×1
q ×1
scala ×1
string ×1