Program to generate an array having convolution of two given arrays | Javascript program for the above approach ; Function to generate a convolution array of two given arrays ; Stores the size of arrays ; Stores the final array ; Traverse the two given arrays ; Update the convolution array ; Print the convolution array c [ ] ; Driver Code
let MOD = 998244353 ; function findConvolution ( a , b ) { let n = a . length , m = b . length ; let c = [ ] ; for ( let i = 0 ; i < n + m - 1 ; ++ i ) { c [ i ] = 0 ; } for ( let i = 0 ; i < n ; ++ i ) { for ( let j = 0 ; j < m ; ++ j ) { c [ i + j ] += ( a [ i ] * b [ j ] ) % MOD ; } } for ( let k = 0 ; k < c . length ; ++ k ) { c [ k ] %= MOD ; document . write ( c [ k ] + " " ) ; } } let A = [ 1 , 2 , 3 , 4 ] ; let B = [ 5 , 6 , 7 , 8 , 9 ] ; findConvolution ( A , B ) ;