I'm trying to understand how the following code works :
Btw this is a solution of this problem:
function getPINs(observed) {
return observed.split('')
.map( t => ({
'0': [ '0', '8' ],
'1': [ '1', '2', '4' ],
'2': [ '1', '2', '3', '5' ],
'3': [ '2', '3', '6' ],
'4': [ '1', '4', '5', '7' ],
'5': [ '2', '4', '5', '6', '8' ],
'6': [ '3', '5', '6', '9' ],
'7': [ '4', '7', '8' ],
'8': [ '5', '7', '8', '9', '0' ],
'9': [ '6', '8', '9' ]
}[t]))
.reduce((pre, cur)=> [].concat.apply([], pre.map(t => cur.map(g => t + g))));
}
when I delete concat method from the code the result is unexpectedly different, as an example, I thought that the result without concat when calling getPINs(456) is [['123'],['125'], ...] instead of [123, 125, ...]