Google Sheets 中的数组和对象与它们之间的距离相关。

huangapple go评论64阅读模式
英文:

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

[ &#39;Op1-Included-Quarterly-100G&#39;,
  &#39;Subop1-Excess-Monthly-10Hits&#39;,
  &#39;Subop2-Included-Monthly-100Hits&#39;,
  &#39;Op3-Flat-Monthly-1Hits&#39;,
  &#39;subop3-Percentage-Monthly-GB&#39;,
  &#39;Op4-Excess-Quarterly-MB&#39;,
  &#39;op5-Flat-Monthly-KB&#39; ]

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

  1. If Included is found in the element add to the object with a value as NA
  2. For an element contains Flat, it should add 2 rows for it
  3. For every other element it should add 16 rows

This is the script I tried

var To_include = {};
const COLUMN_C = &#39;C&#39;;
const START_LINE = 33;
const len = Concat_names.length;
for (var i = 0; i &lt; len; i++) {
      if (Concat_names[i].includes(&quot;Included&quot;)){
        To_include[Concat_names[i]] = &quot;NA&quot;;
      }
      else if((Concat_names[i].includes(&quot;Flat&quot;))){
        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: { &#39;Op1-Included-Quarterly-100G&#39;: &#39;NA&#39;,
  &#39;Subop2-Included-Monthly-100Hits&#39;: &#39;NA&#39;,
  &#39;Subop1-Excess-Monthly-10Hits&#39;: &#39;C49&#39;,
  &#39;Op3-Flat-Monthly-1Hits&#39;: &#39;C39&#39;,
  &#39;subop3-Percentage-Monthly-GB&#39;: &#39;C97&#39;,
  &#39;Op4-Excess-Quarterly-MB&#39; : &#39;C43&#39;,
  &#39;op5-Flat-Monthly-KB&#39;: &#39;C129&#39; }

I want the o/p to be as

To Include: { &#39;Op1-Included-Quarterly-100G&#39;: &#39;NA&#39;,
  &#39;Subop2-Included-Monthly-100Hits&#39;: &#39;NA&#39;,
  &#39;Subop1-Excess-Monthly-10Hits&#39;: &#39;C33&#39;,
  &#39;Op3-Flat-Monthly-1Hits&#39;: &#39;C49&#39;,
  &#39;subop3-Percentage-Monthly-GB&#39;: &#39;C51&#39;,
  &#39;Op4-Excess-Quarterly-MB&#39; : &#39;C67&#39;,
  &#39;op5-Flat-Monthly-KB&#39;: &#39;C83&#39;}

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

        [ &#39;Op1-Included-Quarterly-100G&#39;,
          &#39;Subop1-Excess-Monthly-10Hits&#39;,
          &#39;Subop2-Included-Monthly-100Hits&#39;,
          &#39;Op3-Flat-Monthly-1Hits&#39;,
          &#39;subop3-Percentage-Monthly-GB&#39;,
          &#39;Op4-Excess-Quarterly-MB&#39;,
          &#39;op5-Flat-Monthly-KB&#39; ]
      
    • To

        { &#39;Op1-Included-Quarterly-100G&#39;: &#39;NA&#39;,
          &#39;Subop2-Included-Monthly-100Hits&#39;: &#39;NA&#39;,
          &#39;Subop1-Excess-Monthly-10Hits&#39;: &#39;C33&#39;,
          &#39;Op3-Flat-Monthly-1Hits&#39;: &#39;C49&#39;,
          &#39;subop3-Percentage-Monthly-GB&#39;: &#39;C51&#39;,
          &#39;Op4-Excess-Quarterly-MB&#39; : &#39;C67&#39;,
          &#39;op5-Flat-Monthly-KB&#39;: &#39;C83&#39;}
      

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 = [
  &#39;Op1-Included-Quarterly-100G&#39;,
  &#39;Subop1-Excess-Monthly-10Hits&#39;,
  &#39;Subop2-Included-Monthly-100Hits&#39;,
  &#39;Op3-Flat-Monthly-1Hits&#39;,
  &#39;subop3-Percentage-Monthly-GB&#39;,
  &#39;Op4-Excess-Quarterly-MB&#39;,
  &#39;op5-Flat-Monthly-KB&#39;
];
var To_include = {};
const COLUMN_C = &#39;C&#39;;
const START_LINE = 33;
const len = Concat_names.length;
let offset = 0;
for (var i = 0; i &lt; len; i++) {
  if (Concat_names[i].includes(&quot;Included&quot;)) {
    To_include[Concat_names[i]] = &quot;NA&quot;;
  } else if (Concat_names[i].includes(&quot;Flat&quot;)) {
    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.

huangapple
  • 本文由 发表于 2023年6月9日 13:55:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76437560.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定