title: How to implement array joins in functional way?
body: <p>I have a function that joins an array of objects with a conditional separator.</p>
  
  <pre><code>function getSegmentsLabel(segments) {
      var separator = '-';
  
      var segmentsLabel = '';
      var nextSeparator = '';
      _.forEach(segments, function(segment) {
          segmentsLabel += nextSeparator + segment.label;
          nextSeparator = segment.separatorUsed ? separator : ' ';
      });
      return segmentsLabel;
  }
  </code></pre>
  
  <p><strong>Usages:</strong></p>
  
  <pre><code>var segments = [
      {label: 'First', separatorUsed: true},
      {label: 'Second', separatorUsed: false},
      {label: 'Third', separatorUsed: true},
      {label: 'Forth', separatorUsed: true}
  ];
  
  getSegmentsLabel(segments); // Result: "First-Second Third-Forth"
  </code></pre>
  
  <p>How can the above <code>getSegmentsLabel</code> function be written in a purely functional way without mutating variables? We can use lodash functions.</p>