所以我尝试将这个Python函数转换成Javascript。我不熟悉Python,所以有些语法对我来说很难加密。这是原始代码和我尝试的JS转换。我知道我解释错了,因为我现在所看到的是一个无限循环。在
Python:graph = [[0,1,0,0,1,0],[1,0,1,0,1,0],[0,1,0,1,0,0],[0,0,1,0,1,1],[1,1,0,1,0,0],[0,0,0,1,0,0]]
def N(vertex):
c = 0
l = []
for i in graph[vertex]:
if i is 1 :
l.append(c)
c+=1
return l
def bronk(r,p,x):
if len(p) == 0 and len(x) == 0:
print r
return
for vertex in p[:]:
r_new = r[::]
r_new.append(vertex)
p_new = [val for val in p if val in N(vertex)] #this and
x_new = [val for val in x if val in N(vertex)] #this part was particularly difficult to understand
bronk(r_new,p_new,x_new)
p.remove(vertex)
x.append(vertex)
bronk([], [0,1,2,3,4,5], [])
下面是我将其转换为JS的尝试:
^{pr2}$
我从this问题得到了Python代码。在
编辑:我在一个ES6环境中工作。在