string compare not working in d3.rgb
<p>using RGB color to paint node in d3js sankey chart.
I need to avoid the shades of red color by comparing the return value of the d3.rgb function as not equal to "#ff": Here is my code, kindly let me know what is going wrong. The exception is generated saying str.substring(3,0) not a function</p>

<pre><code>    var str = d3.rgb(d.color).darker(2);
    res = str.substring(3,0)
    while ( res == "#ff")
    {
      console.log("in while");
      str = d3.rgb(d.color).darker(2);
    }
    return str;
</code></pre>