Count forth and back then double up Let's count... 

Count up to 2 and back to 1
Count up to 4 and back to 1
Count up to 6 and back to 1
... ok you got it...

put all these together and you'll get the following sequence 

 {1,2,1,2,3,4,3,2,1,2,3,4,5,6,5,4,3,2,1,2,3,4,5,6,7,8,7,6,5,4,3,2,1,2,3...}


Challenge
Given an integer n&gt;0for 1-indexed (or n&gt;=0 for 0-indexed), output the nth term of this sequence  

Test cases  

Input-&gt;Output  

1-&gt;1  
68-&gt;6  
668-&gt;20  
6667-&gt;63  
10000-&gt;84


Rules

your program must be able to compute solutions up to n=10000 in under a minute

This is code-golf, so the shortest code in bytes wins!
JavaScript (ES7),  59 ... 44  43 bytes
Saved 1 byte thanks to Titus
Expected input: 1-indexed.
n=&gt;(n-=(r=(~-n/2)**.5|0)*r*2)&lt;++r*2?n:r*4-n

Initially inspired by a formula for A004738, which is a similar sequence. But I ended up rewriting it entirely.
Test cases


let f=

n=&gt;(n-=(r=(~-n/2)**.5|0)*r*2)&lt;++r*2?n:r*4-n

console.log(f(1))     // -&gt; 1
console.log(f(68))    // -&gt; 6
console.log(f(668))   // -&gt; 20
console.log(f(6667))  // -&gt; 63
console.log(f(10000)) // -&gt; 84



How?
The sequence can be arranged as a triangle, with the left part in ascending order and the right part in descending order.
Below are the first 4 rows, containing the first 32 terms:
            1 | 2
        1 2 3 | 4 3 2
    1 2 3 4 5 | 6 5 4 3 2
1 2 3 4 5 6 7 | 8 7 6 5 4 3 2

Now, let's introduce some variables:
 row  | range   | ascending part              | descending part
 r    | x to y  | 1, 2, ..., i                | 4(r+1)-(i+1), 4(r+1)-(i+2), ...
------+---------+-----------------------------+-----------------------------------------
  0   |  1 -  2 |                           1 | 4-2
  1   |  3 -  8 |                   1   2   3 | 8-4  8-5  8-6
  2   |  9 - 18 |           1   2   3   4   5 | 12-6 12-7 12-8  12-9  12-10
  3   | 19 - 32 |   1   2   3   4   5   6   7 | 16-8 16-9 16-10 16-11 16-12 16-13 16-14

We start with 2 elements at the top and add 4 elements on each new row. Therefore, the number of elements on the 0-indexed row r can be expressed as:
a(r) = 4r + 2

The 1-indexed starting position x of the row r is given by the sum of all preceding terms in this arithmetic series plus one, which leads to:
x(r) = r * (2 + a(r - 1)) / 2 + 1
     = r * (2 + 4(r - 1) + 2) / 2 + 1
     = 2r² + 1

Reciprocally, given a 1-indexed position n in the sequence, the corresponding row can be found with:
r(n) = floor(sqrt((n - 1) / 2))

or as JS code:
r = (~-n / 2) ** 0.5 | 0

Once we know r(n), we subtract the starting position x(r) minus one from n:
n -= r * r * 2

We compare n with a(r) / 2 + 1 = 2r + 2 to figure out whether we are in the ascending part or in the descending part:
n &lt; ++r * 2 ?

If this expression is true, we return n. Otherwise, we return 4(r + 1) - n. But since r was already incremented in the last statement, this is simplified as:
n : r * 4 - n