'I am not able to understand the code
I am new to javascript. After lots of hours I am not able to understand the code. I would be grateful if someone could help me. Thanks
for(var x = 0; x < id_inters['inters'].length; x++) {
var a,b;
if(id_inters['inters'][x]['First_ID'] == data.main[0].cust) {
a = id_inters['inters'][x]['First_ID'];
b = id_inters['inters'][x]['Second_ID2'];
Solution 1:[1]
You can take it with these steps from the for loop:
- var x is declared and assigned value of 0.
- There will be an Object named
id_inters
which hold an array namedinters
which also holds objects in it. - Now inside the loop you declare two variables
var a, b;
. - Now that n the condition you are checking the value of the iterated object with
id_inters['inters'][x]['First_Id']
wherex
is the index number if each iteration which is incremented from 0 to length of array. - And you are checking each iterated value to the first value of the
data['main'][0].cust
. Where data is an object which contains an array named data and you are comparing its first object's cust value.
Solution 2:[2]
You are given an array A of size N.
A partitioning of the array A is the splitting of A into one or more non-empty contiguous subarrays such that each element of A belongs to exactly one of these subarrays.
Find the number of ways to partition A such that the parity of the sum of elements within the subarrays is alternating. In other words, if Si denotes the sum of the elements in the i-th subarray, then either
S1 is odd, S2 is even, S3 is odd and so on. or S1 is even, S2 is odd, S3 is even and so on. For example if A=[1,2,3,3,5]. One way to partition A is [1,2][3,3][5]. Another way to partition A is [1][2][3][3,5]. Note that there exists more ways to partition this array.
Since the answer may be large, output it modulo 998244353.
Input Format The first line contains a single integer T - the number of test cases. Then the test cases follow. The first line of each test case contains an integer N - the size of the array A. The second line of each test case contains N space-separated integers A1,A2,…,AN denoting the array A. Output Format For each test case, output the answer modulo 998244353.
Constraints 1?T?10000 1?N?2?105 0?Ai?109 Sum of N over all test cases does not exceed 2?105 Sample Input 1 3 3 1 2 3 4 4 4 4 4 5 1 2 3 3 5 Sample Output 1 2 1 5 Explanation Test case 1: The array can be partitioned as follows
[1][2][3] [1,2,3] Test case 2: The array can be partitioned as follows
[4,4,4,4]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Abhishek Saini |