arr = [[1,2,3],[4,5,6],[7,8,9]]
For javascript:
var result = 1 in arr.flat();
For python:
var result = any(1 in sub for sub in arr);
arr = [[1,2,3],[4,5,6],[7,8,9]]
For javascript:
var result = 1 in arr.flat();
For python:
var result = any(1 in sub for sub in arr);
| JS | Python |
|---|---|
let arr = []; |
arr = [] |
let arr = new Array(5); |
arr = [None] * 5 |
arr.push(1); |
arr.append(1); |
arr.unshift(2); arr.splice(0, 0, 2); |
arr[:0]=[2] arr.insert(0,2) |
arr.splice(2,0,3,4); |
arr[1:0]=[3] |
let arr3 = arr1.concat(arr2); |
arr3 = arr1 + arr2 |
arr = [...arr, ...otherArr]; |
arr = [*arr, *otherArr] arr.extend(otherArr) |
arr.pop(); |
arr.pop() |
arr.splice(0,1); |
arr[0:1]=[] |
arr.shift(); |
arr.pop(0) |
arr.splice(1,1); |
arr[1:2]=[] arr.pop(1) |
arr = new Array(5).fill(0); |
arr = [0] * 5 |
[...Array(5).keys()].map(i=>i+5); |
list(range(5,10) |
arr[0] |
arr[0] |
arr.slice(-1)[0]; |
arr[-1] |
arr.slice(0, N); |
arr[0: N] |
Array.isArray(arr) |
isinstance(arr, list) |
arr = s.split("");
arr = [...s]; |
arr = list(s) |
s = arr.join("");
|
s = "".join(arr) |
Here is my solution. It's break a loop into three sections:
1. Find the new begin number to construct new interval.
2. Find the new end number to construct new interval.
3. Append the remaining items into new interval.
Hope this make sense.
Also, hope those if/else conditions can be more straight forward.
Try to get one step further. Now, just put newInterval into array in order.
Then swap the end number.
The logic in here is getting more straight forward.
Initial two dimension array with 0L
> arr = Array(2).fill(Array(10).fill(0));
[
[
0, 0, 0, 0, 0,
0, 0, 0, 0, 0
],
[
0, 0, 0, 0, 0,
0, 0, 0, 0, 0
]
However, assign a data that populate all rows in that position.
> arr[1][2]=3;
3
> arr
[
[
0, 0, 3, 0, 0,
0, 0, 0, 0, 0
],
[
0, 0, 3, 0, 0,
0, 0, 0, 0, 0
]
]
Initial two dimension array with sequence number:
> arr = Array(2).fill(Array(10).fill(0)).map((a,i)=>a.map((b,j)=>i*10+j));
[
[
0, 1, 2, 3, 4,
5, 6, 7, 8, 9
],
[
10, 11, 12, 13, 14,
15, 16, 17, 18, 19
]
]
Reassigning a data is fine in here.
> arr[1][2] = 77;
77
> arr
[
[
0, 1, 2, 3, 4,
5, 6, 7, 8, 9
],
[
10, 11, 77, 13, 14,
15, 16, 17, 18, 19
]
]
<div style="display: none; visibility: hidden;" id="msg">
Deleting this category will lose all articles.
Do you really want to do it?</div>
<SCRIPT>
function confirmDeletion() {
var msg = document.getElementById("msg").innerHTML.replace(/
/ig,"\n");
if (confirm(msg) ) {
....
form.submit();
}
return false;
}
</SCRIPT>