2015-06-04 32 views
1

您好我正在尝试编写一个谷歌电子表格自定义函数。它收到一个范围并吐出干净的rootdomain。我只是遇到了“太多的处决” - 我必须在整张表格上运行它。所以我增加了一个范围。谷歌电子表格自定义功能代码不工作:= RootDomain

现在反馈是“内部错误功能” ......

帮助表示赞赏....这必须是可能的!

/** 
* Generates clean root domains 
* 
* @param {input} input The value to change to a root domain. 
* @return The clean root domain. 
* @RootDomain 
*/ 
function RootDomain(input) { 
    if (input == null) return ''; 
    if (input.map) {   // Test whether input is an array. 
    return input.map(RootDomain); // Recurse over array if so. 
    } else { 
    if (input = '') return ''; 
    regex = new RegExp(/((www)\.)?.*(\w+)\.([\w\.]{2,6})/); 
    return regex.exec(input)[0].replace(/^http(s)?:\/\//i, "").replace(/^www\./i, "").replace(/\/.*$/, ""); 
    } 
} 
+0

变化**如果(输入= '')返回 ''; **的**,如果(输入=== '')返回 ''; * *。当您仅使用一个'='号时,您正在将**输入**设置为空 –

+0

THX!问题是,有三个===它比较字符串,但如果INPUT为空(当没有输入或单元格为空时)会发生什么 – SNH

+0

不,用===它会检查输入是否为空。你在做什么是做你不想要的输入。 –

回答

1

而是执行此操作:

function RootDomain(input) { 
    if (input == null || input === '') { 
    return ''; 
    } else if (input.map) {   // Test whether input is an array. 
    return input.map(RootDomain); // Recurse over array if so. 
    } 
    var regex = new RegExp(/((www)\.)?.*(\w+)\.([\w\.]{2,6})/); 
    return regex.exec(input)[0].replace(/^http(s)?:\/\//i, "").replace(/^www\./i, "").replace(/\/.*$/, ""); 
    } 
+0

适用于1单元。现在做了:= rootdomain(D2:D10000 ),因为否则我们会遇到一个计算问题“计算太多”或什么的,现在的错误是#REF – SNH

+0

为什么你甚至要做100000行? –