
var request = require('request');
var markov = require('markov');
var fs = require('fs');

function get(){
    request('https://www.reddit.com/r/unitedkingdom.json', function (error, response, body) {
        //console.log('error:', error); // Print the error if one occurred
        //return response.statusCode // Print the response status code if a response was received
        let s = []
        JSON.parse(body).data.children.forEach( item => {
            s.push(item.data.title)
        })
        build(s)
      });
}


function build(s){
    var m = markov(1)
    while (true){
        m.seed(s.join())
        // console.log(m.pick())
        console.log(m.respond(" ").join(' ').split(',')[3])
    }

}

get()