Skip to content

Planeshifter/guess-age

Repository files navigation

NPM version Build Status Coverage Status Dependencies

guess-age

Guess the age of a person only from their first name.

Installation

$ npm install guess-age

For use in the browser, use browserify.

Usage

var guess = require( 'guess-age' );

guess( name[, gender] )

Retrieves the median and interquartile range of the age of all persons with a certain name estimated to be currently living in the US.

var out;

out = guess( 'Noah' );
/*
	{
		median: 9,
		iqr: [ 4, 15.004656730414027 ]
	}
*/

out = guess( 'Jack' );
/*
	{
		median: 50.04038167193148,
		iqr: [ 11.092877845442404, 70.04441983912463 ]
	}
*/

Since some names can be given to both boys and girls, there is some ambiguity in the gender associated with a name. The function supports an optional gender argument which should be used if the gender is known. If the gender argument is omitted, the statistics are calculated separately for each gender group and then a weighted average is computed based on the distribution of the two genders for persons with the name in question.

out = guess( 'Lindsay', 'male' );
/*
	{
		iqr: [ 35, 62 ],
		median: 53
	}
*/

out = guess( 'Lindsay', 'female' );
/*
	{
		iqr: [ 21, 32 ],
		median: 27
	}
*/

Reference

See the article on FiveThirtyEight which was the inspiration for this module. The statistics are based on data collected by the Social Security Administration, namely their actuarial tables and data on birth frequencies.

Examples

var guess = require( 'guess-age' ),
	out;

// Statistics for Herbert:
out = guess( 'Herbert' );

// Statistics for Jason:
out = guess( 'Jason' );

// Statistics for Connor:
out = guess( 'Connor' );

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.

About

Guess the age of a person only from their first name.

Resources

License

Stars

Watchers

Forks

Packages

No packages published