Last active
August 24, 2017 08:55
-
-
Save nitinreddy3/da39345ddb9e616134454b56761191f4 to your computer and use it in GitHub Desktop.
Get a 'n' number of elements from an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Method to filter out first 'n' elements from an array.