如何在每次迭代数组

时间:2015-07-31 03:43:07

标签: javascript jquery arrays loops

每次迭代数组时的父子组合

我太困惑了,太困难了也无法弄清楚可以做些什么。

这是我的问题

如果我有10个节点(可以是N,例如我可以提及为10),如果一次选择一个循环并且无法再次选择组合节点,则也无法选择交叉循环。

他们可以有[(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7)(8) ,8)(9,9)(10,10)]自循环组合,两个节点循环组合也包含自循环[(1,2)(3,4)(5,6)(7,8)(9) ,10)]或[(2,3)(5,6)(9,10),(1,1)....]和3节点循环与子自循环和2节点循环也有自循环和4节点循环使用子节点2节点或子节点自我节点循环,这些循环

父母子女组合是最致命的部分:[(1,5)(2,4)(3,3)(6,10)(7,9)(8,8)]

所以我只想写逻辑,因为在上面的数组中我会得到每一个我将它们推入数组

Eg: In 10 Nodes if user Selects 2 and 4 i would set the array as follows

[(startIndex:2,endIndex:4,depthOfLoop:1)]

Now he cannot touch 2 and 4 again or internal 3 node to Which forms a cross Loop

if the user selects 6 and 9 then i need to match the before array object 

this 6 and 9 goes into the newStartIndex and newEndIndex
As per My Assumptions generally i would get 4 Comparisions

for ChildLoop:-(newStartIndex>startIndex && newEndIndex<endIndex)
for ParentLoop:-(newStartIndex<startIndex && newEndIndex>endIndex)
for SameCategoryLoop:-((newStartIndex<startIndex && newEndIndex<startIndex)/(newStartIndex>endIndex&& newEndIndex>endIndex))

for SameCategoryLoop Previous Array DepthOfLoop Becomes same to the newArray which is 6,9 is checked with 2,4 and goes into ((newStartIndex>endIndex&& newEndIndex>endIndex)) then My Array would be as follows

[(startIndex:2,endIndex:4,depthOfLoop:1)(startIndex:6,endIndex:9,depthOfLoop:1)]

然后在下一次迭代中,如果用户选择1和5,我需要验证这个newStartIndex和newEndIndex以及两个对象startIndex和endIndex,我需要决定depthOfLoop

> It comes into two category. 
> One is ParentLoop:-(newStartIndex<startIndex && newEndIndex>endIndex) based on (2,4) and 
> Another is SameCategoryLoop ((newStartIndex<startIndex &&newEndIndex<startIndex) based on (6,9). 
> Now i need to switch between depthOfLoops too.

在推入数组时,我需要为每一次迭代找到父子组合,这需要用数组对象中的所有值进行验证。

这是我面临的主要问题,请向Logic提出建议,这可能对我有所帮助

请帮忙。

0 个答案:

没有答案