Skip to content

Instantly share code, notes, and snippets.

@caleywoods
Created September 18, 2012 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caleywoods/e651c32039dfdc60635d to your computer and use it in GitHub Desktop.
Save caleywoods/e651c32039dfdc60635d to your computer and use it in GitHub Desktop.
/* This adds two methods first() and last() to Arrays.
* These methods are used throughout this file, removing
* them will cause things to break. If these need to be
* removed you need to replace first() with Array[0] and last
* with Array[array.length - 1]
*/
Array.prototype.first = function () { return this[0]; };
Array.prototype.last = function () { return this[this.length - 1]; };
/* This adds a method to String objects that allows you to test
* whether or not a certain character or string exists in a target
* string. In raw JS you need to check for .indexOf("test") !== -1
*/
String.prototype.contains = function( it ) { return this.indexOf( it ) !== -1; };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment