This came up while talking to a friend and I thought I\'d ask here since it\'s an interesting problem and would like to see other people\'s solutions.
The task is to
validParentheses: function validParentheses(n) { if(n === 1) { return ['()']; } var prevParentheses = validParentheses(n-1); var list = {}; prevParentheses.forEach(function(item) { list['(' + item + ')'] = null; list['()' + item] = null; list[item + '()'] = null; }); return Object.keys(list); }