Conditional concatenate of a cell range
<p>I am trying to set up a conditional multi-concatenate and am almost there.</p>

<p>The principle is (like a SUMIF) you run along one row/column and if the value matches the condition you take the corresponding value from the sum range and add them together. Though this time we're concatenating them (literally adding them together!)
This picture shows the expected result and my actual result which should explain better than I can. 
<a href="https://i.stack.imgur.com/z1wY4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z1wY4.png" alt="Spreadsheet"></a>
The issue I'm having is that no matter what I input as the last parameter it still gives a comma without any space (inputting "#" still gives a comma etc)...</p>

<p>Here's the code: </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>/**
 * Concatenates a range of cells where the condition is met.
 *
 * @param {A4:A6} cRange The dynamic cell range to test.
 * @param {"Condition"} cCondition The string that the cell should match.
 * @param {A4:A6} pRange The dynamic cell range to concatenate.
 * @param {", "} interspace A string to insert between each entry.
 * @return The a concatenated range of cells
 * @customfunction
 */
function conditionalMultiConcat(cRange, cCondition, pRange, interspace){  
   var ss = SpreadsheetApp.getActiveSpreadsheet(); //get the active workbook
   var sheet = ss.getSheets()[0]; //get the active sheet
   //var values = sheet.getRange(pRange).getValues(); //debug line - uncomment to see the values
   var values = "" //set the return value to blank
   for(var cc = 0; cc &lt; pRange.length; ++cc) { //For each value in the array
     if ((cc == 0 || cc == pRange.length - 1) &amp;&amp; (cRange[cc] = cCondition)) { //if it's the first or last value AND it matches our condition
       values = values + pRange[cc].toString();// concatenate without interspace
     }
     else if (cRange[cc] = cCondition){ //else if it matches our condition then concatenate with the interspace
       values = values + interspace + pRange[cc].toString();// concatenate
     }
   }
  return values;
}</code></pre>
</div>
</div>
</p>

<p>What am I missing here?
Thanks.</p>