Initialize the array with - 1
for ( let row = 0 ; row < dp . length ; row ++ ) { dp [ row ] = new Array ( dp . length ) ; for ( let column = 0 ; column < dp . length ; column ++ ) { dp [ row ] [ column ] = - 1 ; } } document . write ( " " + ( s1 . length - transformation ( s1 , s2 , 0 , 0 ) ) ) ; document . write ( " " + ( s2 . length - transformation ( s1 , s2 , 0 , 0 ) ) ) ; document . write ( " " + transformation ( s1 , s2 , 0 , 0 ) ) ;