{"size": 1034, "ext": "js", "max_stars_repo_path": "src/index.js", "max_stars_repo_name": "MakouskiYan/love-triangle", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/index.js", "max_issues_repo_name": "MakouskiYan/love-triangle", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/index.js", "max_forks_repo_name": "MakouskiYan/love-triangle", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.4117647059, "max_line_length": 103, "alphanum_fraction": 0.6228239845}
/**
 * @param preferences - an array of integers. Indices of people, whom they love
 * @returns number of love triangles
 */
module.exports = function getLoveTrianglesCount(preferences = []) {
  var i = 0;
  var count = 0;
  function findTriangle(x){
    //theese variables were made because every array start it's indexes from 0 and we need start from 1
    var a = x+1;
    var b = preferences[a-1];
    var c = preferences[b-1];
    var d = preferences[c-1];
    //that rule was made for not cycling on one number array or triangles should
    //be consisted from 3 different numbers!
    if(a===d && a!==b && b!==c && c!==d){
      //it's made for not including numbers from previous counted triangles,
      // if we just delete them, we will change indexes of every number. 
      preferences[a-1] = "x";
      preferences[b-1] = "x";
      preferences[c-1] = "x";
      count+=1;
      return true;
    }else{
      return false;
    }
  }
  while(i<=preferences.length-1){
    findTriangle(i);
    i++;
  }
  return count;
};
