我想将两种不同类型的Xml元素反序列化为一个List,因为我想保留顺序
@RequiresApi
目前我正在使用以下内容将这两个动作合并到一个列表中,但我必须将元素名称更改为NewAction(如上所述),而不是将Action更改为第二个
<Step name="Login to Account" >
<Action name="LoginToWebsite" type="Login" />
<NewAction name="EnterTextInTextBox" type="SendKeysToTextBox" extraAttribute="Testvalue" />
</Step>
由于XmlAnyElement被绑定到&#34; Action&#34;元素名称,如何更改为支持两个不同的元素名称,但需要反序列化为一个数组
答案 0 :(得分:1)
你想要的是
var input = ['a','b','c','d','a','d','e','e','f','h','h','h','i','l','m','n','r','s','s','t','u','v','y','y'];
function group(arr) {
var hash = {};
return arr.reduce(function(res, e) {
if(hash[e] === undefined) // if we haven't hashed the index for this value
hash[e] = res.push([e]) - 1; // then hash the index which is the index of the newly created array that is initialized with e
else // if we have hashed it
res[hash[e]].push(e); // then push e to the array at that hashed index
return res;
}, []);
}
console.log(group(input));