1>>> import js2py
2>>> f = js2py.eval_js('function f(x) {return x + x}')
3>>> f(2)
44
5>>> f()
6nan
7>>> f(f)
8function f(x) { [python code] }function f(x) { [python code] }
1function solution(arr) {
2 if (arr && arr.length > 0) {
3 let visitedNum = new Set();
4
5 let result = arr.every((num) => {
6 if (visitedNum.has(num - 1) || visitedNum.has(num + 1)) {
7 return 0;
8 }
9
10 visitedNum.add(num);
11
12 return 1;
13 });
14
15 return !result;
16 }
17
18 return 0;
19}
1def numberOfSubArray(arr):
2 data = {}
3 n = len(arr)
4 maxAmount = 1
5 for i in range(1, n + 1):
6 for j in range(i):
7 s = sum(arr[j:i])
8 if s not in data:
9 data[s] = [i - 1, 1]
10 elif data[s][0] < j:
11 data[s][1] += 1
12 if data[s][1] > maxAmount: maxAmount = data[s][1]
13 data[s][0] = i - 1
14
15 return maxAmount