Thue-Morse: Difference between revisions

No edit summary
Line 299:
}</lang>
<pre>0110100110010110100101100110100110010110011010010110100110010110</pre>
 
 
=={{header|JavaScript}}==
 
===ES6===
<lang JavaScript>(() => {
'use strict';
 
// THUE MORSE
 
// thueMorse :: Int -> String
let thueMorse = nCycles => range(1, Math.abs(nCycles))
.reduce(a => a.concat(a.map(x => 1 - x)), [0])
.join('');
 
 
// GENERIC FUNCTION
 
// range :: Int -> Int -> [Int]
let range = (m, n) => Array.from({
length: Math.floor((n - m)) + 1
}, (_, i) => m + i);
 
 
// TEST
 
return thueMorse(6);
 
// 0110100110010110100101100110100110010110011010010110100110010110
 
})();
</lang>
 
{{Out}}
<pre></pre>
 
=={{header|Lua}}==
9,659

edits