假设我有两个列表,列表letters
,包含字母A-F,列表nums
,包含数字1-6。如何在Elm中使用循环构建列表?
在Elm中,我该如何编程列出包含每种可能组合(即A1,C6,F3,D2等)的列表?
这只是为了代码优雅的目的,硬编码的每一种可能的组合都是等价的。
在JavaScript中,它会通过类似表示...
const nums = [1,2,3,4,5,6];
const letters = [`a`,`b`,`c`,`d`,`e`,`f`];
const combineLists = (a,b)=>{
const newList = [];
a.forEach(aEl=>{
b.forEach(bEl=>{
newList.push(aEl + bEl);
})
})
return newList;
}
console.log(combineLists(letters,nums));
你怎么会写在榆树等效combineLists
功能?
我很欣赏的方式如何实现' combineLists' functio –