Javascript Data Structure

Source: Internet
Author: User


There is an array [0.5, 3]. You can find out the number of frequencies that match the maximum number of frequencies/array length>, if yes, place the subscript Of this number. If no-1 is returned
VaR A = [5, 3, 4, 6, 3, 3]
For (VAR I = 0, CI, r = {}; CI = A [I]; I ++ ){
If (R [CI]) {
R [CI]. idx. Push (I );
R [CI]. Count ++;
} Else {
R [CI] = {idx: [I], Count: 1}
}
}
VaR F =-1, L = A. length;
For (VAR p in r ){
If (R [p]. Count/L> 0.5) F = R [p]. idx;
}
Alert (f );
There is an array [5, 0,-5,-4, 5], and a positive or negative number is calculated. The frequency of each number is calculated.
VaR A = [5, 3, 4, 6,-3,-3]
For (VAR I = 0, CI, r = {}; CI = A [I ++];) {
If (R [math. Abs (CI)]) {
R [math. Abs (CI)] ++
} Else {
R [math. Abs (CI)] = 1;
}
}
VaR S = [];
For (VAR p in r ){
S. Push (R [p]);
}
Alert (s );
Subsequences with sequences [5, 0, 2,-6, 4] can have [5, 0], [5, 0, 2] [2,-6], [5, 0, 2, -6, 4], but not [5, 2], [5,-6]
Returns the sum of the largest sequences. In this example, the largest sequence is [5, 0, 2] = 7.
VaR A = [-6, 0, 2, 5, 4], max = 0;
For (VAR I = 0, L = A. length; I <L-1; I ++ ){
For (var j = I; j <L; j ++ ){
For (var tmp = 0, K = I; k <= J; k ++ ){
TMP = TMP + A [k];
}
If (TMP> MAX) max = TMP;
}
}
Alert (max );
Winter reply
Question 1 <textarea id="runcode21773"></textarea>
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]

If you do not consider the convenient JavaScript Object, then ......
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]

Third bug with full negative number
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.