{"size": 820, "ext": "js", "max_stars_repo_path": "Challenges/fizzBuzzTree/fizz-buzz-tree.js", "max_stars_repo_name": "shadykh/data-structures-and-algorithms", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Challenges/fizzBuzzTree/fizz-buzz-tree.js", "max_issues_repo_name": "shadykh/data-structures-and-algorithms", "max_issues_repo_issues_event_min_datetime": "2021-05-22T12:32:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-22T12:32:05.000Z", "max_forks_repo_path": "Challenges/fizzBuzzTree/fizz-buzz-tree.js", "max_forks_repo_name": "shadykh/data-structures-and-algorithms", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 16.0784313725, "max_line_length": 63, "alphanum_fraction": 0.5682926829}
'use strict';

const Node = require('./node.js');

const Tree = require('./tree.js');

function FizzBuzzTree (tree) {

  if (!tree.root){
    return 'The Tree is empty !!';
  }

  let newTree = new Tree();

  let fizzingBuzzing = (node)=>{

    let treeNode = new Node(null);

    if (node.value % 3 === 0 && node.value % 5 === 0){

      treeNode.value = 'FizzBuzz';

    } else if (node.value % 3 === 0){

      treeNode.value = 'Fizz';

    } else if (node.value % 5 === 0){

      treeNode.value = 'Buzz';

    } else {
      treeNode.value = `${node.value}`;
    }

    for (let i = 0; i < node.children.length; i++){

      treeNode.children.push(fizzingBuzzing(node.children[i]));
    }

    return treeNode;

  }; 

  newTree.root = fizzingBuzzing(tree.root);


  return newTree;

}

module.exports=FizzBuzzTree;