Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#JavaScript (ES6), 108 bytes
Takes input as (array)(n). Returns either an array or false.
(array)(n)
false
a=>n=>a.reduce((a,x)=>[...a,...a.map(y=>1/r[(y=[...y]).push(x)]||eval(y.join`+`)-n?y:r=y)],[[]],r=!n&&[])&&r
Try it online!
#JavaScript (ES6), 111108 bytes
a=>n=>a.reduce((a,x)=>[...a,...a.map(y=>y=>1/r[(b=[y=[...y,x],1/r[by]).length]||evalpush(bx)]||eval(y.join`+`)-n?by:r=b)r=y)],[[]],r=!n&&[])&&r
Try it online!Try it online!
#JavaScript (ES6), 111 bytes
a=>n=>a.reduce((a,x)=>[...a,...a.map(y=>(b=[...y,x],1/r[b.length]||eval(b.join`+`)-n?b:r=b))],[[]],r=!n&&[])&&r
#JavaScript (ES6), 119111 bytes
a=>n=>a.reduce(m=(a,x)=>[...a,...a.map(y=>(b=[...y,x],eval1/r[b.length]||eval(b.join`+`)-n|m>(l=b.length)n?b:(m=l,r=b)))],[[]],r=!n&&[])&&r
#JavaScript (ES6), 119 bytes
a=>n=>a.reduce(m=(a,x)=>[...a,...a.map(y=>(b=[...y,x],eval(b.join`+`)-n|m>(l=b.length)?b:(m=l,r=b)))],[[]],r=!n&&[])&&r