title: algorithm to find the nth character of DA,B(n)
body: <p>Here is the description of my problem. For any two string variables, A and B, we define FA,B to be the sequence (A,B,AB,BAB,ABBAB,...) in which each term is the concatenation of the previous two.</p>
  
  <p>Further, we define DA,B(n) to be the nth digit in the first term of FA,B that contains at least n digits.</p>
  
  <p>Example :</p>
  
  <p>Let A="1415", B="8979". n = 10 We wish to find DA,B(n), say.</p>
  
  <p>The first few terms of FA,B are:</p>
  
  <p>"1415"</p>
  
  <p>"8979"</p>
  
  <p>"14158979"</p>
  
  <p>"897914158979"</p>
  
  <p>"9" is the answer</p>
  
  <p>Write an algorithm to find the nth character of DA,B(n)</p>
  
  <p>These things are need to fulfill when write a solution. </p>
  
  <ol>
  <li>The return type should be a string.</li>
  <li>getNthPosition("1415","8979",10) Should equal to 9</li>
  <li>getNthPosition("abc","435d",100) Should equal to b</li>
  <li>The answer should be valid for any given input</li>
  </ol>
  
  <p>1 and 2 requirments are complteted but i don't have idea about how to do 3rd requirment. any suggession. Thanks. </p>
  
  <p>here is my code:</p>
  
  <pre><code>function getNthPosition(a,b,n) {
  let output = '';  
   var tot2,ans;
  
    tot2 = b + a;
    ans = b+a+b; 
  
    for(var i = 0; i&lt;=ans.length - 1; i++){
  
  
      output += ans[i].split("").sort().join('');
  
  
      output += "";
    }
  
    var nNumber = ans[n - 1];
  
    return nNumber;
  
  }
  
  console.log(getNthPosition("1415","8979",10));
  </code></pre>