重新分配的参数

时间:2018-06-11 23:17:06

标签: javascript google-apps-script

我试图从电子邮件中删除显示名称,例如

library(tidyverse) df %>% mutate(class = case_when( status == 0 & lag(status) == 1 & lag(status, n = 2L) == 1 ~ "a", status == 1 & lag(status) == 0 ~ "b", TRUE ~ "c")) # Trank status class #1 1 0 c #2 2 1 b #3 3 0 c #4 4 0 c #5 5 1 b #6 6 1 c #7 7 0 a #8 8 1 b #9 9 0 c #10 10 1 b minikube start --extra-config=kubelet.Authentication.Anonymous.Enabled=true --extra-config=kubelet.Authentication.Webhook.Enabled=false --extra-config=kubelet.Authorization.Mode=AlwaysAllow

Steve<steve@steve.com>

一旦代码退出stripEmail,参数电子邮件就会更改为结果。我也注意到在其他一些功能中也会发生这种情况。当我尝试使用变量时,这会导致奇怪的问题。

变量testemail设置: enter image description here

一旦我跨过该功能,testemail就会被更改。 {{3}}

1 个答案:

答案 0 :(得分:0)

如果要避免更改原始数组,请避免将一个数组设置为等于另一个数组。而不是重用email变量,创建一个新的输出变量。在下面的代码中,电子邮件将放入名为result的新数组中。

stripEmail函数处理字符串和数组,并且总是返回一个与源数组不同的数组,而原始数组保持不变。

代码可以更改为:

function test1() {
  var testemail = ["Steve<steve@steve.com>","displayname<display@steve.com>"];
  Logger.log('testemail: ' + testemail)

  var debug = stripEmail(testemail);

  Logger.log('debug: ' + debug)
  Logger.log('testemail: ' + testemail)
}

function stripEmail(email) {
  var arr,i,part1,result;

  result = [];

  //Give me an email with a display name and I will strip out the display name
  //"<Steve Gon> stevegon@google.com"
  if (typeof email === 'string') {
    email = email.split(",");
  }

  for (i=0; i<email.length; i++) {
    if (email[i].search("<")>-1) {//If there is no less than, then it doesn't have a display name
      part1 = email[i].split("<");

      if (part1.length == 2) {
        result[i] = part1[1].replace(">","");
        result[i] = result[i].replace("<","");
        result[i] = result[i].replace(" ","");
      } 
    } 
  }

  return result;
}