Created
November 14, 2017 16:42
-
-
Save vineeshnp/2ec451dc1e3f8d2f25d51b39e5aadeae to your computer and use it in GitHub Desktop.
Prints all sub array of an array - Bruteforce
This file contains 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
/** | |
* Creates all the sub arrays of a give array | |
* @params {Array} arr | |
* @returns {Array} | |
*/ | |
function getSubArray(arr){ | |
let arrLen = arr.length; | |
let result = []; | |
for(let subLen = degree; subLen <= arrLen; subLen++){ | |
for(let begin = 0; begin+subLen <=arrLen; begin++){ | |
result.push(arr.slice(begin,begin+subLen)); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment