Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed challenge #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

completed challenge #15

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 17, 2016

I used protoyping to monkey patch the Array class, so that all my arrays would have a .sample() function similar to Ruby's .sample method. It's definitely not the only way to solve the problem, but it does demonstrate how prototyping can be used to extend existing classes.

this.last_names = ['the Chef', 'Digital', 'Wise', 'Knight', 'Wrecka', 'the Genius', 'the Zoo Keeper', 'the Monk', 'the Scientist', 'the Disciple', 'the Darkman', 'Pellegrino', 'the Ill Figure', 'Rocks The World', 'the Baptist',];
this.first_names = ['Inspectah', 'Masta', 'Poppa', 'Five Foot', 'Ghostface', 'Old Dirty'];
// add a .sample() function to our array objects
Array.prototype.sample = function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@ghost
Copy link
Author

ghost commented Jan 18, 2016

My random number generation logic is slightly off in the .sample() function. I'll fix that, nice catch!

@ghost ghost changed the title completed exercise completed challenge Feb 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant