{"size": 2120, "ext": "js", "max_stars_repo_path": "Games/GuessingGame_Mewwaa/utils.js", "max_stars_repo_name": "VamsiKrishna04/Hacktoberfest_2021-1", "max_stars_repo_stars_event_min_datetime": "2021-10-02T07:10:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T08:38:27.000Z", "max_issues_repo_path": "Games/GuessingGame_Mewwaa/utils.js", "max_issues_repo_name": "VamsiKrishna04/Hacktoberfest_2021-1", "max_issues_repo_issues_event_min_datetime": "2021-10-01T17:03:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-20T07:31:36.000Z", "max_forks_repo_path": "Games/GuessingGame_Mewwaa/utils.js", "max_forks_repo_name": "VamsiKrishna04/Hacktoberfest_2021-1", "max_forks_repo_forks_event_min_datetime": "2021-10-01T22:03:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-28T08:38:31.000Z"}
{"max_stars_count": 21, "max_issues_count": 19, "max_forks_count": 115, "avg_line_length": 21.2, "max_line_length": 215, "alphanum_fraction": 0.6160377358}
var fs = require('fs-extra');

class Question {
    constructor(index, contents, answer) {
        this.index = index;
        this.contents = contents;
        this.answer = 'true';
    }

    getId() {
        return this.index
        
    }

    getContent() {
        return this.contents
    }

}

class answers {
    constructor(answer) {
        this.answer = answer;
    }

    getAnswear() {
        return this.answer
        
    }

}

function readDb(path) {
    fs.ensureFileSync(path);
    let table = fs.readJsonSync(path, { throws: false });
    if (table === null) {
        return [];
    }
    return table;
}

function saveToDb(path, table) {
    fs.writeJsonSync(path, table);
}
    
function generateNewQuestion(index ,contents, answer) {
    let odp = new Question(index, contents, answer);
    return odp;

}

function answerQuestions(answer) {
    let pyt = new answers(answer);
    return pyt;

}

function checkIfTrue(answer) {
    if (answer !== 'true')
        return false;
    return true;
}

function checkIfGoodId(id) {
    if (id !== 1)
        return false;
    return true;
}

function getCurrentQuestionId(ques) {
    let queIds = [];
    for (let index = 0; index < ques.length; index++) {
        const que = ques[index];
        queIds.push(que.index);
    }
    return queIds;
}

function getCurrentQuestionContent(ques) {
    let queCons = [];
    for (let index = 0; index < ques.length; index++) {
        const que = ques[index];
        queCons.push(que.contents);
    }
    return queCons;
}

// function modifyQuestion(index, content, answer) {
//     if (!checkIfGoodId(content.getCurrentQuestionContent())) {
//         console.log('You can only modify questions with id: 1');
//         return undefined;
//     }

//     const changedContent = newQuestion /  content.getContent();
    
//     return new Question(index, changedContent, answer);
// }


module.exports = { readDb,saveToDb, Question, answers,generateNewQuestion, checkIfGoodId,getCurrentQuestionContent,checkIfTrue, answerQuestions, getCurrentQuestionId} // to pozwala uzywać tych metod w innych plikach