start new:
tmux
start new with session name:
tmux new -s myname
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| time node ./lib/permutations.js | |
| # getPermutations('abcdefghij') // => abcdefghij, abcdefghji, abcdefgihj, abcdefgijh, abcdefgjhi, abcdefgjih, abcdefhgij... | |
| # // n = 10, f(n) = 3,628,800; | |
| # ./lib/permutations.js 8.06s user 0.63s system 101% cpu 8.562 total |
| getPermutations('ab') // ab, ba... | |
| // n = 2, f(n) = 2; | |
| getPermutations('abc') // abc, acb, bac, bca, cab, cba... | |
| // n = 3, f(n) = 6; | |
| getPermutations('abcd') // abcd, abdc, acbd, acdb, adbc, adcb, bacd... | |
| // n = 4, f(n) = 24; | |
| getPermutations('abcde') // abcde, abced, abdce, abdec, abecd, abedc, acbde... | |
| // n = 5, f(n) = 120; |
| function getPermutations(string, prefix = '') { | |
| if(string.length <= 1) { | |
| return [prefix + string]; | |
| } | |
| return Array.from(string).reduce((result, char, index) => { | |
| const reminder = string.slice(0, index) + string.slice(index+1); | |
| result = result.concat(getPermutations(reminder, prefix + char)); | |
| return result; | |
| }, []); |
| getPermutations('a') // => [ 'a'] | |
| getPermutations('ab') // => [ 'ab', 'ba'] | |
| getPermutations('abc') // => [ 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' ] |
| powerset('') // ... | |
| // n = 0, f(n) = 1; | |
| powerset('a') // , a... | |
| // n = 1, f(n) = 2; | |
| powerset('ab') // , a, b, ab... | |
| // n = 2, f(n) = 4; | |
| powerset('abc') // , a, b, ab, c, ac, bc, abc... | |
| // n = 3, f(n) = 8; | |
| powerset('abcd') // , a, b, ab, c, ac, bc, abc, d, ad, bd, abd, cd, acd, bcd... | |
| // n = 4, f(n) = 16; |
| function powerset(n = '') { | |
| const array = Array.from(n); | |
| const base = ['']; | |
| const results = array.reduce((previous, element) => { | |
| const previousPlusElement = previous.map(el => { | |
| return `${el}${element}`; | |
| }); | |
| return previous.concat(previousPlusElement); | |
| }, base); |
| function hasDuplicates(n) { | |
| const duplicates = []; | |
| let counter = 0; // debug | |
| for (let outter = 0; outter < n.length; outter++) { | |
| for (let inner = 0; inner < n.length; inner++) { | |
| counter++; // debug | |
| if(outter === inner) continue; |
| powerset('') // => [''] | |
| powerset('a') // => ['', 'a'] | |
| powerset('ab') // => ['', 'a', 'b', 'ab'] |