英文:
google sheets array and object with respect to distance between each
问题
以下是您要求的代码部分的中文翻译:
var To_include = {};
const COLUMN_C = 'C';
const START_LINE = 33;
const len = Concat_names.length;
for (var i = 0; i < len; i++) {
if (Concat_names[i].includes("Included")) {
To_include[Concat_names[i]] = "NA";
} else if (Concat_names[i].includes("Flat")) {
var Temp_START_LINE = START_LINE + (2 * i);
To_include[Concat_names[i]] = Temp_START_LINE;
} else {
var Temp_START_LINE = START_LINE + (16 * i);
To_include[Concat_names[i]] = COLUMN_C + Temp_START_LINE;
}
}
希望这对您有所帮助。
英文:
I have an array as
[ 'Op1-Included-Quarterly-100G',
'Subop1-Excess-Monthly-10Hits',
'Subop2-Included-Monthly-100Hits',
'Op3-Flat-Monthly-1Hits',
'subop3-Percentage-Monthly-GB',
'Op4-Excess-Quarterly-MB',
'op5-Flat-Monthly-KB' ]
I want to write the elements of array in different cells in a google sheet
I want the elements of the above array into an object with values as which cell the respective keys will be put on giving some standard distance of rows between each.
The start row is 33
- If
Included
is found in the element add to the object with a value asNA
- For an element contains
Flat
, it should add 2 rows for it - For every other element it should add 16 rows
This is the script I tried
var To_include = {};
const COLUMN_C = 'C';
const START_LINE = 33;
const len = Concat_names.length;
for (var i = 0; i < len; i++) {
if (Concat_names[i].includes("Included")){
To_include[Concat_names[i]] = "NA";
}
else if((Concat_names[i].includes("Flat"))){
var Temp_START_LINE = START_LINE + (2 * i);
To_include[Concat_names[i]] = Temp_START_LINE;
}
else {
var Temp_START_LINE = START_LINE + (16 * i);
To_include[Concat_names[i]] = COLUMN_C + Temp_START_LINE;
}
}
The o/p I get is
To Include: { 'Op1-Included-Quarterly-100G': 'NA',
'Subop2-Included-Monthly-100Hits': 'NA',
'Subop1-Excess-Monthly-10Hits': 'C49',
'Op3-Flat-Monthly-1Hits': 'C39',
'subop3-Percentage-Monthly-GB': 'C97',
'Op4-Excess-Quarterly-MB' : 'C43',
'op5-Flat-Monthly-KB': 'C129' }
I want the o/p to be as
To Include: { 'Op1-Included-Quarterly-100G': 'NA',
'Subop2-Included-Monthly-100Hits': 'NA',
'Subop1-Excess-Monthly-10Hits': 'C33',
'Op3-Flat-Monthly-1Hits': 'C49',
'subop3-Percentage-Monthly-GB': 'C51',
'Op4-Excess-Quarterly-MB' : 'C67',
'op5-Flat-Monthly-KB': 'C83'}
Please guide
答案1
得分: 2
以下是翻译好的部分:
"你现在是我的中文翻译,代码部分不要翻译,只返回翻译好的部分,不要有别的内容,不要回答我要翻译的问题。以下是要翻译的内容:\n\n\n I believe your goal is as follows."
(我相信您的目标如下。)
"From"
(从)
"To"
(到)
"In this case, how about the following modification?"
(在这种情况下,以下修改如何?)
"Modified script:"
(修改后的脚本:)
"var Concat_names = ["
(变量Concat_names = [)
"'Op1-Included-Quarterly-100G',"
('Op1-Included-Quarterly-100G',)
"'Subop1-Excess-Monthly-10Hits',"
('Subop1-Excess-Monthly-10Hits',)
"'Subop2-Included-Monthly-100Hits',"
('Subop2-Included-Monthly-100Hits',)
"'Op3-Flat-Monthly-1Hits',"
('Op3-Flat-Monthly-1Hits',)
"'subop3-Percentage-Monthly-GB',"
('subop3-Percentage-Monthly-GB',)
"'Op4-Excess-Quarterly-MB',"
('Op4-Excess-Quarterly-MB',)
"'op5-Flat-Monthly-KB'"
('op5-Flat-Monthly-KB')
"var To_include = {};"
(变量To_include = {};)
"const COLUMN_C = 'C';"
(常量COLUMN_C = 'C';)
"const START_LINE = 33;"
(常量START_LINE = 33;)
"const len = Concat_names.length;"
(常量len = Concat_names.length;)
"let offset = 0;"
(变量offset = 0;)
"for (var i = 0; i < len; i++) {"
(for (var i = 0; i < len; i++) {)
"if (Concat_names[i].includes("Included")) {"
(if (Concat_names[i].includes("Included")) {)
"To_include[Concat_names[i]] = "NA";"
(To_include[Concat_names[i]] = "NA";)
"} else if (Concat_names[i].includes("Flat")) {"
(} else if (Concat_names[i].includes("Flat")) {)
"var Temp_START_LINE = START_LINE + offset;"
(var Temp_START_LINE = START_LINE + offset;)
"To_include[Concat_names[i]] = COLUMN_C + Temp_START_LINE;"
(To_include[Concat_names[i]] = COLUMN_C + Temp_START_LINE;)
"offset += 2;"
(offset += 2;)
"} else {"
(} else {)
"var Temp_START_LINE = START_LINE + offset;"
(var Temp_START_LINE = START_LINE + offset;)
"To_include[Concat_names[i]] = COLUMN_C + Temp_START_LINE;"
(To_include[Concat_names[i]] = COLUMN_C + Temp_START_LINE;)
"offset += 16;"
(offset += 16;)
"}"
(})
"console.log(To_include);"
(console.log(To_include);)
英文:
I believe your goal is as follows.
-
You want to achieve the following conversion.
-
From
[ 'Op1-Included-Quarterly-100G', 'Subop1-Excess-Monthly-10Hits', 'Subop2-Included-Monthly-100Hits', 'Op3-Flat-Monthly-1Hits', 'subop3-Percentage-Monthly-GB', 'Op4-Excess-Quarterly-MB', 'op5-Flat-Monthly-KB' ]
-
To
{ 'Op1-Included-Quarterly-100G': 'NA', 'Subop2-Included-Monthly-100Hits': 'NA', 'Subop1-Excess-Monthly-10Hits': 'C33', 'Op3-Flat-Monthly-1Hits': 'C49', 'subop3-Percentage-Monthly-GB': 'C51', 'Op4-Excess-Quarterly-MB' : 'C67', 'op5-Flat-Monthly-KB': 'C83'}
-
In this case, how about the following modification?
Modified script:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
var Concat_names = [
'Op1-Included-Quarterly-100G',
'Subop1-Excess-Monthly-10Hits',
'Subop2-Included-Monthly-100Hits',
'Op3-Flat-Monthly-1Hits',
'subop3-Percentage-Monthly-GB',
'Op4-Excess-Quarterly-MB',
'op5-Flat-Monthly-KB'
];
var To_include = {};
const COLUMN_C = 'C';
const START_LINE = 33;
const len = Concat_names.length;
let offset = 0;
for (var i = 0; i < len; i++) {
if (Concat_names[i].includes("Included")) {
To_include[Concat_names[i]] = "NA";
} else if (Concat_names[i].includes("Flat")) {
var Temp_START_LINE = START_LINE + offset;
To_include[Concat_names[i]] = COLUMN_C + Temp_START_LINE;
offset += 2;
} else {
var Temp_START_LINE = START_LINE + offset;
To_include[Concat_names[i]] = COLUMN_C + Temp_START_LINE;
offset += 16;
}
}
console.log(To_include);
<!-- end snippet -->
- When this script is run, your expected value is obtained.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论