{"size": 923, "ext": "js", "max_stars_repo_path": "2018/once.js", "max_stars_repo_name": "Jacob-Friesen/obscurejs", "max_stars_repo_stars_event_min_datetime": "2015-01-23T05:14:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T13:31:57.000Z", "max_issues_repo_path": "2018/once.js", "max_issues_repo_name": "Jacob-Friesen/obscurejs", "max_issues_repo_issues_event_min_datetime": "2015-02-09T01:25:44.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-03T01:52:05.000Z", "max_forks_repo_path": "2018/once.js", "max_forks_repo_name": "Jacob-Friesen/obscurejs", "max_forks_repo_forks_event_min_datetime": "2015-05-07T19:46:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-03T20:57:37.000Z"}
{"max_stars_count": 65, "max_issues_count": 2, "max_forks_count": 9, "avg_line_length": 15.9137931034, "max_line_length": 51, "alphanum_fraction": 0.6446370531}
'use strict';

console.log('Not once limited:');

function once(callback) {
  let called = false,
    result = undefined;
  return () => {
    if (called === false) {
      result = callback(...arguments);
    }
    called = true;
    return result;
  }
}

let value = 0;
function increment() {
  value += 1;
  return value;
}

console.log(increment());
// 1
console.log(increment());
// 2
console.log(increment());
// 3

console.log('\nOnce limited in a custom way:');

let called = false;
function oneTimeIncrement() {
  if (!called) {
    value += 1;
  }
  called = true;

  return value;
}

console.log(oneTimeIncrement());
// 4
console.log(oneTimeIncrement());
// 4
console.log(oneTimeIncrement());
// 4

console.log('\nOnce limited in a generalized way');

const oneTimeIncrement2 = once(increment);
console.log(oneTimeIncrement2());
// 4
console.log(oneTimeIncrement2());
// 4
console.log(oneTimeIncrement2());
// 4
