Created
December 27, 2014 07:55
-
-
Save suguru03/fad9fc37c6517bd290f8 to your computer and use it in GitHub Desktop.
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
function combinationLoop(list, choose, callback) { | |
(function loop(result, nest, index, length) { | |
while (index <= length + nest - choose) { | |
(nest === 0 ? (result = []) : result)[nest] = list[index++]; | |
if (nest < choose - 1) { | |
loop(result, nest + 1, index, length); | |
} else { | |
callback(result.concat()); // 状況に応じて不要 | |
} | |
} | |
})(null, 0, 0, list.length); | |
} | |
combinationLoop(['A', 'B', 'C', 'D', 'E'], 3, function(list) { | |
console.log(list); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment