Skip to content

Instantly share code, notes, and snippets.

@nitinreddy3
Last active August 24, 2017 08:55
Show Gist options
  • Save nitinreddy3/da39345ddb9e616134454b56761191f4 to your computer and use it in GitHub Desktop.
Save nitinreddy3/da39345ddb9e616134454b56761191f4 to your computer and use it in GitHub Desktop.
Get a 'n' number of elements from an array
/**
* Filters out first 'n' elements from the list
*/
/**
* Represents a array
*/
var list = [ 1, 2, 3, 4, 5, 6, 7, 6, 3, 4, 5, 12, 123, 2, 2, 23, 4, 5, 67, 4, 2, 34, 23, 34, 5, 45];
/**
* Represents a filterArray method.
* @ constructor
* @param {array} arrayItem - An array containing some elements
*/
filterArray(arrayItem) {
var list = []
var n = 8;
for(var i = 0; i < n ; i++) {
list.push(arrayItem[i])
}
return list
}
/**
* Call the function and pass an array
* @param {list}
*/
filterArray(list)
// [1, 2, 3, 4, 5, 6, 7, 6, 3, 4, 5, 12, 123, 2, 2, 23, 4, 5, 67, 4]
@nitinreddy3
Copy link
Author

Method to filter out first 'n' elements from an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment