Skip to content

Instantly share code, notes, and snippets.

@vineeshnp
Created November 14, 2017 16:42
Show Gist options
  • Save vineeshnp/2ec451dc1e3f8d2f25d51b39e5aadeae to your computer and use it in GitHub Desktop.
Save vineeshnp/2ec451dc1e3f8d2f25d51b39e5aadeae to your computer and use it in GitHub Desktop.
Prints all sub array of an array - Bruteforce
/**
* 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