I'm trying to sort an array of "tile" objects in as3 by the value of its "realY" property.
This is my code:
tiles.sortOn("realY", Array.DESCENDING);
tiles.reverse();
for each(var t:Tile in tiles)
{
trace(t.nearness);
}
This is the output:
6
6
6
6
6
7
7
7
7
7
7
8
8
8
8
8
8
8
9
9
9
9
9
9
9
9
10
10
10
10
10
10
10
10
10
11
11
11
11
11
11
11
11
11
11
12
12
12
12
12
12
12
12
12
12
12
13
13
13
13
13
13
13
13
13
13
13
13
14
14
14
14
14
14
14
14
14
14
14
14
14
15
15
15
15
15
15
15
15
15
15
15
15
15
15
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16
17
17
17
17
17
17
17
17
17
17
17
17
17
17
17
17
18
18
18
18
18
18
18
18
18
18
18
18
18
18
18
18
18
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
21
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
22
23
23
23
23
23
23
23
23
23
23
23
23
23
23
23
23
23
23
24
24
24
24
24
24
24
24
24
24
24
24
24
24
24
24
24
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
25
26
26
26
26
26
26
26
26
26
26
26
26
26
26
26
27
27
27
27
27
27
27
27
27
27
27
27
27
27
28
28
28
28
28
28
28
28
28
28
28
28
28
29
29
29
29
29
29
29
29
29
29
29
29
30
30
30
30
30
30
30
30
30
30
30
2
31
31
31
31
31
31
31
31
31
31
32
32
32
32
32
32
32
32
32
33
33
33
33
33
33
33
33
34
34
34
34
34
34
34
35
35
35
35
35
35
36
36
36
36
36
37
37
37
37
38
38
38
39
39
40
3
3
4
4
4
5
5
5
5
As you can see, there are some random small numbers at the end. Why is this happening?
Thanks
Try using your sortOn like this:
tiles.sortOn("realY", Array.NUMERIC | Array.DESCENDING);
By default Flash is sorting in alphabetical order. Check the documentation for more info.
Besides that, you're tracing the nearness property, not the realY property you sorted. So maybe that's a problem too.
Related
How can I append multiple rows from source sheet to destination sheet; select columns like A,C,H ?
source sheet columns A-Z, with multiple rows.
destination sheet - append rows from source sheet - select columns A, C and H only.
Thank you
Transfer Data from one sheet to another selecting only columns A,C and H
function xferdata() {
const ss = SpreadsheetApp.getActive();
const ssh = ss.getSheetByName("Sheet0");
const dsh = ss.getSheetByName("Sheet1");
const vs = ssh.getRange(2,1,ssh.getLastRow() - 1, 8).getValues();
let o = vs.map(([a,,c,,,,,h]) => [a,c,h]);
//Logger.log(JSON.stringify(o));
dsh.getRange(dsh.getLastRow() + 1,1,o.length,o[0].length).setValues(o);
}
Sheet0:
COL1
COL2
COL3
COL4
COL5
COL6
COL7
COL8
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
9
3
4
5
6
7
8
9
10
4
5
6
7
8
9
10
11
5
6
7
8
9
10
11
12
6
7
8
9
10
11
12
13
7
8
9
10
11
12
13
14
8
9
10
11
12
13
14
15
9
10
11
12
13
14
15
16
10
11
12
13
14
15
16
17
11
12
13
14
15
16
17
18
12
13
14
15
16
17
18
19
13
14
15
16
17
18
19
20
14
15
16
17
18
19
20
21
15
16
17
18
19
20
21
22
16
17
18
19
20
21
22
23
17
18
19
20
21
22
23
24
18
19
20
21
22
23
24
25
19
20
21
22
23
24
25
26
20
21
22
23
24
25
26
27
Sheet1:
A
B
C
1
3
8
2
4
9
3
5
10
4
6
11
5
7
12
6
8
13
7
9
14
8
10
15
9
11
16
10
12
17
11
13
18
12
14
19
13
15
20
14
16
21
15
17
22
16
18
23
17
19
24
18
20
25
19
21
26
20
22
27
I have the following challenge so far I know how to use the Reduce Method to sum all values in one dim array.
var sum = array.reduce((accumulator, currentValue) => {
return accumulator + currentValue; });
But how can I use this Method on an 2d array? For example I want to sum all items from the 5. column in the 2d Array.
Not complete sure if this is want you're looking for
function sumfive() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet0');
const [h, ...v] = sh.getDataRange().getValues();
let sum = v.reduce((a, r) => {
let row = 0;
r.forEach((c, i) => {
if (i > 4) { row += Number(c); }
});
a.sum += row;
return a;
}, { sum: 0, getSum: function () { return this.sum; } }).getSum();
Logger.log(sum);
}
Data:
COL1
COL2
COL3
COL4
COL5
COL6
COL7
COL8
COL9
COL10
COL11
COL12
COL13
COL14
COL15
COL16
COL17
COL18
COL19
COL20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Execution log
11:37:54 AM Notice Execution started
11:37:55 AM Info 6750.0
11:37:56 AM Notice Execution completed
I have the following 'nested set' data in a table.
ID
name
lft
rgt
main
1
Occasion uurwerken
1
28
1
2
Mechanisch
2
27
3
Alpine
3
4
4
AS
5
6
5
Durowe
7
8
6
Enicar
9
10
7
ETA
11
12
8
FE
13
14
9
FEF
15
16
10
Felsa
17
18
11
FHF
19
20
12
Otero
21
22
13
Peseux
23
24
14
PUW
25
26
15
Nieuwe uurwerken
29
60
1
16
Quartz
30
47
17
Catlin
31
32
18
Citizen
33
34
19
ESA
35
36
20
FE
37
38
21
GUB
39
40
22
Miyota
41
42
23
Parrenin
43
44
24
Ronda
45
46
25
Mechanisch
48
59
26
Enicar
49
50
27
FE
51
52
28
FHF
53
54
29
Pesseux
55
56
30
Ronda
57
58
31
Vintage occasion
61
66
1
32
Certina stemvork
62
63
33
Tissot stemvork
64
65
I have this query to retrieve the data I need for building a menu
SELECT parent.name AS parentname, node.id, node.name AS name, node.lft, node.rgt, (
COUNT( parent.name ) -1) AS depth
FROM nested_menu AS node, nested_menu AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.id
ORDER BY node.lft";
Which works fine and returns the following data
parentname
ID
name
lft
rgt
depth
Occasion uurwerken
1
Occasion uurwerken
1
28
0
Occasion uurwerken
2
Mechanisch
2
27
1
Occasion uurwerken
3
Alpine
3
4
2
Occasion uurwerken
4
AS
5
6
2
Occasion uurwerken
5
Durowe
7
8
2
Occasion uurwerken
6
Enicar
9
10
2
Occasion uurwerken
7
ETA
11
12
2
Occasion uurwerken
8
FE
13
14
2
Occasion uurwerken
9
FEF
15
16
2
Occasion uurwerken
10
Felsa
17
18
2
Occasion uurwerken
11
FHF
19
20
2
Occasion uurwerken
12
Otero
21
22
2
Occasion uurwerken
13
Peseux
23
24
2
Occasion uurwerken
14
PUW
25
26
2
Nieuwe uurwerken
15
Nieuwe uurwerken
29
60
0
Nieuwe uurwerken
16
Quartz
30
47
1
Nieuwe uurwerken
17
Catlin
31
32
2
Nieuwe uurwerken
18
Citizen
33
34
2
Nieuwe uurwerken
19
ESA
35
36
2
Nieuwe uurwerken
20
FE
37
38
2
Nieuwe uurwerken
21
GUB
39
40
2
Nieuwe uurwerken
22
Miyota
41
42
2
Nieuwe uurwerken
23
Parrenin
43
44
2
Nieuwe uurwerken
24
Ronda
45
46
2
Nieuwe uurwerken
25
Mechanisch
48
59
1
Nieuwe uurwerken
26
Enicar
49
50
2
Nieuwe uurwerken
27
FE
51
52
2
Nieuwe uurwerken
28
FHF
53
54
2
Pesseux
29
Pesseux
55
56
2
Ronda
30
Ronda
57
58
2
Vintage occasion
31
Vintage occasion
61
66
0
Certina stemvork
32
Certina stemvork
62
63
1
Tissot stemvork
33
Tissot stemvork
64
65
1
Which seems fine, but in the rows with ID 29 and 30 the parent name is suddenly the same as the node name and I have no clue why?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I created a form and tried to search for records but with no success
[This is my sheet link][1]
[1]: https://docs.google.com/spreadsheets/d/1FyM3xaDE6LhdHSxwIBrw-NAx1Mcn_Dezzgi_JWJtDWU/edit?usp=sharing
var SEARCH_COL_IDX=0;
function Search(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formS = ss.getSheetByName('フォーム');
//var data = ss.getSheetByName('データ管理');
var str= formS.getRange("M3").getValue();
var values= ss.getSheetByName("データ管理").getDataRange().getValues();
for(var i=0;i<values.length;i++){
var row= values[i];
if(row[SEARCH_COL_IDX] == str){
formS.getRange("D3").setValue(row[0]);//title
formS.getRange("D7").setValue(row[1]);//ID
formS.getRange("D9").setValue(row[2]);//daytime
formS.getRange("I9").setValue(row[3]);//Check data
formS.getRange("D13").setValue(row[4]);//input1
formS.getRange("D21").setValue(row[5]);//input2
formS.getRange("D30").setValue(row[6]);//input3
formS.getRange("D39").setValue(row[7]);//input4
formS.getRange("C50").setValue(row[8]);//Implementation date
formS.getRange("C55").setValue(row[9]);//Date of enactment
formS.getRange("J50").setValue(row[10]);//管理者
formS.getRange("J55").setValue(row[11]);//制定者
}
}
}
This is basically the same thing and it works:
function testfunc() {
var ss = SpreadsheetApp.getActive();
var sh2 = ss.getSheetByName('Sheet2');
var str = sh2.getRange('A1').getValue();//get search value for col1
var vs = ss.getSheetByName('Sheet1').getDataRange().getValues();
vs.forEach(r => {
if (r[0] == str) {
sh2.appendRow(r);//I appended the row because it's easier
}
});
}
My Sheet1:
COL1
COL2
COL3
COL4
COL5
COL6
COL7
COL8
COL9
COL10
6
12
4
21
6
19
23
20
2
18
12
4
15
1
25
15
7
14
15
2
18
16
22
10
19
19
3
20
29
12
24
28
7
13
12
11
27
26
11
4
0
28
6
0
14
2
23
25
23
28
5
23
7
16
6
29
9
9
12
22
23
15
5
7
7
14
17
9
10
0
4
1
0
25
16
2
19
24
20
12
19
8
3
2
20
22
28
14
8
15
16
6
23
24
18
17
20
2
13
12
24
5
23
29
19
17
23
10
22
12
8
11
25
6
15
2
7
14
10
17
21
29
4
25
9
27
0
15
29
19
4
28
16
15
4
19
16
7
6
15
19
17
0
5
23
11
26
18
16
2
14
2
7
6
16
21
18
26
29
1
17
8
29
1
1
15
11
12
24
20
22
19
6
13
1
6
6
29
5
26
17
7
24
1
18
7
21
20
26
29
16
28
9
12
21
16
7
5
8
9
5
7
27
23
12
9
19
18
20
26
22
15
23
4
27
29
16
15
22
17
25
7
19
15
17
18
24
25
7
2
7
18
14
1
10
23
14
1
29
3
11
5
22
9
0
26
4
23
23
4
10
12
16
19
28
6
25
0
0
14
24
9
18
9
29
19
8
8
11
22
20
29
23
15
0
27
14
19
2
22
18
18
2
22
24
7
26
20
11
23
15
7
17
15
12
6
15
24
8
21
My Sheet2:
22
Search Value
22
19
6
13
1
6
6
29
5
26
22
15
23
4
27
29
16
15
22
17
Please i need help to calculate moving average in SSRS. see example from excel bellow. i have search net and looked at other forum without success.
the moving average is something like Avg(A1:A3),Avg(A2:A4),Avg(A3:A5)etc
Count of ID BAND
-20 >20 <12 Grand Total Three Months Avg
Year Month <15 15-20 >20 Total
2012/2013 Jan 35 9 13 57 57
Feb 34 23 20 77 67
Mar 25 33 8 66 =AVERAGE(F5:F7)
Apr 7 31 13 51 65
May 6 10 13 29 49
Jun 19 14 18 51 44
Jul 34 16 6 56 45
Aug 26 21 30 77 =AVERAGE(F10:F12)
Sep 13 53 21 =AVERAGE(F11:F13)
Oct 1 34 33 68 =AVERAGE(F12:F14)
Nov 35 16 19 70 53
Dec 33 23 36 92 77