我知道之前已经问过这种问题,但是一般的解决方法
$($("input").get().reverse()).each(function() { /* ... */ });
Run Code Online (Sandbox Code Playgroud)
不适合我.我有一个xml文档,其中包含我要在网页上显示的音乐会列表.所以,在JQuery中:
$.ajax({
type: "GET",
url: "concerts.xml",
dataType: "xml",
cache: false,
success: function(xml) {
$(xml).find('concert').each(function() {
/*do stuff*/
});
}
});
Run Code Online (Sandbox Code Playgroud)
但是,我想以相反的顺序显示音乐会.所以,我尝试了以下,但它不起作用:
$.ajax({
type: "GET",
url: "concerts.xml",
dataType: "xml",
cache: false,
success: function(xml) {
$($(xml).find('concert').reverse()).each(function() {
/*do stuff*/
});
}
});
Run Code Online (Sandbox Code Playgroud)
任何援助将不胜感激.谢谢.
我正在尝试编写一个高阶函数来包装输入函数并缓存最近调用的结果作为副作用。基本函数 ( withCache) 看起来像这样:
function cache(key: string, value: any) {
//Some caching logic goes here
}
function withCache<R>(key: string, fn: (...args: any[]) => R): (...args: any[]) => R {
return (...args) => {
const res = fn(...args);
cache(key, res);
return res;
}
}
const foo = (x: number, y: number) => x + y;
const fooWithCache = withCache("foo", foo);
let fooResult1 = fooWithCache(1, 2); // allowed :)
let fooResult2 = fooWithCache(1, 2, 3, 4, 5, 6) // also allowed …Run Code Online (Sandbox Code Playgroud) 我正在为多类分类器(m个数据点,k个类)构建输入.在我的输入中,我将训练数据的标签作为向量y中的整数(即y是m维,y中的每个条目是1和k之间的整数).
我想将其转换为m x k矩阵.每行在索引处对应于该数据点的标签处为1,否则为0(例如,如果数据点具有标签3,则该行看起来像[0 0 1 0 0 0 0 ...]).
我可以通过构造一个矢量a = [1 2 3 4 ... k]然后计算来做到这一点
M_ = y*(1./b)
M = M_ .== 1
Run Code Online (Sandbox Code Playgroud)
(./元素划分在哪里,.==元素逻辑等于).这通过将中间矩阵中的所有内容设置为不完全为1到0来实现我想要的.
但这个解决方案似乎很愚蠢.有没有更直接的方式让我失踪?
我想使用参数扩展获取foo给定文件的直接父目录的名称,例如给定/home/blah/foo/bar.txt.现在我可以用两行来做:
f="/home/blah/foo/bar.txt"
dir_name="${f%/*}"
immediate_parent="${dir_name##*/}"
Run Code Online (Sandbox Code Playgroud)
但我对参数扩展很新,所以我认为这可以进行优化.有没有办法只用一行呢?
bash ×1
generics ×1
javascript ×1
jquery ×1
matlab ×1
matrix ×1
octave ×1
shell ×1
typescript ×1
vector ×1