repl.it
@mcuringa/

Collatz

ES6

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function seq3np1(n) {

  let sequence = "";
  while (n !== 1) {
    sequence += n + ", ";
    if (n % 2 === 0) {  // n is even 
      n = Math.floor(n / 2);
    }
    else {         // n is odd 
      n = n * 3 + 1;
    }
  }
  console.log(sequence + 1 + ".");
}

seq3np1(3);
seq3np1(16);
seq3np1(25);
seq3np1(13);

Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie
?