dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let i = 0 ; function isLeaf ( pre , n , min , max ) { if ( i >= n ) { return false ; } if ( pre [ i ] > min && pre [ i ] < max ) { i ++ ; let left = isLeaf ( pre , n , min , pre [ i - 1 ] ) ; let right = isLeaf ( pre , n , pre [ i - 1 ] , max ) ; if ( ! left && ! right ) { document . write ( pre [ i - 1 ] + " " ) ; } return true ; } return false ; } function printLeaves ( preorder , n ) { isLeaf ( preorder , n , Number . MIN_VALUE , Number . MAX_VALUE ) ; } let preorder = [ 890 , 325 , 290 , 530 , 965 ] ; let n = preorder . length ; printLeaves ( preorder , n ) ;

Index/key variables: i
Accumulator variables: i
Javascript program:
class Node { constructor ( ) { this . key = 0 ; this . left = null ; this . right = null ; this . parent = null ; } } function newNode ( item ) { var temp = new Node ( ) ; temp . key = item ; temp . left = null ; temp . right = null ; temp . parent = null ; return temp ; } function inorder ( root ) { if ( root != null ) { inorder ( root . left ) ; document . write ( " " + root . key + " " ) ; if ( root . parent == null ) document . write ( " " ) ; else document . write ( " " + root . parent . key + " " ) ; inorder ( root . right ) ; } } function insert ( node , key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) { var lchild = insert ( node . left , key ) ; node . left = lchild ; lchild . parent = node ; } else if ( key > node . key ) { var rchild = insert ( node . right , key ) ; node . right = rchild ; rchild . parent = node ; } return node ; } var root = null ; root = insert ( root , 50 ) ; insert ( root , 30 ) ; insert ( root , 20 ) ; insert ( root , 40 ) ; insert ( root , 70 ) ; insert ( root , 60 ) ; insert ( root , 80 ) ; inorder ( root ) ;

Class/struct names: Node
Javascript program:
function pairs ( arr , n , k ) { var smallest = 1000000000 ; var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) { if ( Math . abs ( arr [ i ] + arr [ j ] - k ) < smallest ) { smallest = Math . abs ( arr [ i ] + arr [ j ] - k ) ; count = 1 ; } else if ( Math . abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ; } document . write ( " " + smallest + " " ) ; document . write ( " " + count + " " ) ; } var arr = [ 3 , 5 , 7 , 5 , 1 , 9 , 9 ] ; var k = 12 ; var n = arr . length ; pairs ( arr , n , k ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
var a = [ 5 , 1 , 14 , 4 , 15 , 9 , 7 , 20 , 11 ] ; var key = 20 ; var arraySize = a . length ; var count = 0 ; for ( i = 0 ; i < arraySize ; i ++ ) { if ( a [ i ] <= key ) { count += 1 ; } } document . write ( " " + key + " " + ( count - 1 ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
class Node { constructor ( d ) { this . info = d ; this . left = this . right = null ; } } let head ; let count = 0 ; function insert ( node , info ) { if ( node == null ) { return ( new Node ( info ) ) ; } else { if ( info <= node . info ) { node . left = insert ( node . left , info ) ; } else { node . right = insert ( node . right , info ) ; } return node ; } } function check ( num ) { let sum = 0 , i = num , sum_of_digits , prod_of_digits ; if ( num < 10 num > 99 ) return 0 ; else { sum_of_digits = ( i % 10 ) + Math . floor ( i / 10 ) ; prod_of_digits = ( i % 10 ) * Math . floor ( i / 10 ) ; sum = sum_of_digits + prod_of_digits ; } if ( sum == num ) return 1 ; else return 0 ; } function countSpecialDigit ( rt ) { let x ; if ( rt == null ) return ; else { x = check ( rt . info ) ; if ( x == 1 ) count = count + 1 ; countSpecialDigit ( rt . left ) ; countSpecialDigit ( rt . right ) ; } } let root = null ; root = insert ( root , 50 ) ; root = insert ( root , 29 ) ; root = insert ( root , 59 ) ; root = insert ( root , 19 ) ; root = insert ( root , 53 ) ; root = insert ( root , 556 ) ; root = insert ( root , 56 ) ; root = insert ( root , 94 ) ; root = insert ( root , 13 ) ; countSpecialDigit ( root ) ; document . write ( count ) ;

Class/struct names: Node
Javascript program:
var MAX = 100 ; function middlesum ( mat , n ) { var row_sum = 0 , col_sum = 0 ; for ( i = 0 ; i < n ; i ++ ) row_sum += mat [ parseInt ( n / 2 ) ] [ i ] ; document . write ( " " + row_sum + " " ) ; for ( i = 0 ; i < n ; i ++ ) col_sum += mat [ i ] [ parseInt ( n / 2 ) ] ; document . write ( " " + col_sum ) ; } var mat = [ [ 2 , 5 , 7 ] , [ 3 , 7 , 2 ] , [ 5 , 6 , 9 ] ] ; middlesum ( mat , 3 ) ;

Index/key variables: i
Accumulator variables: col_sum, i, row_sum
Iterator variables: i
Javascript program:
var M = 3 ; var N = 3 ; function rotateMatrix ( matrix , k ) { var temp = Array ( M ) . fill ( 0 ) ; k = k % M ; for ( i = 0 ; i < N ; i ++ ) { for ( t = 0 ; t < M - k ; t ++ ) temp [ t ] = matrix [ i ] [ t ] ; for ( j = M - k ; j < M ; j ++ ) matrix [ i ] [ j - M + k ] = matrix [ i ] [ j ] ; for ( j = k ; j < M ; j ++ ) matrix [ i ] [ j ] = temp [ j - k ] ; } } function displayMatrix ( matrix ) { for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < M ; j ++ ) document . write ( matrix [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } var matrix = [ [ 12 , 23 , 34 ] , [ 45 , 56 , 67 ] , [ 78 , 89 , 91 ] ] ; var k = 2 ; rotateMatrix ( matrix , k ) ; displayMatrix ( matrix ) ;

Index/key variables: i, j, t
Accumulator variables: i, j, t
Iterator variables: i, j, t
Javascript program:
function interchangeFirstLast ( m ) { let rows = m . length ; for ( let i = 0 ; i < m [ 0 ] . length ; i ++ ) { let t = m [ 0 ] [ i ] ; m [ 0 ] [ i ] = m [ rows - 1 ] [ i ] ; m [ rows - 1 ] [ i ] = t ; } } let m = [ [ 8 , 9 , 7 , 6 ] , [ 4 , 7 , 6 , 5 ] , [ 3 , 2 , 1 , 8 ] , [ 9 , 9 , 7 , 7 ] ] interchangeFirstLast ( m ) ; for ( let i = 0 ; i < m . length ; i ++ ) { for ( let j = 0 ; j < m [ 0 ] . length ; j ++ ) document . write ( m [ i ] [ j ] + " " ) ; document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function sortRowWise ( m ) { for ( let i = 0 ; i < m . length ; i ++ ) { for ( let j = 0 ; j < m [ i ] . length ; j ++ ) { for ( let k = 0 ; k < m [ i ] . length - j - 1 ; k ++ ) { if ( m [ i ] [ k ] > m [ i ] [ k + 1 ] ) { let t = m [ i ] [ k ] ; m [ i ] [ k ] = m [ i ] [ k + 1 ] ; m [ i ] [ k + 1 ] = t ; } } } } for ( let i = 0 ; i < m . length ; i ++ ) { for ( let j = 0 ; j < m [ i ] . length ; j ++ ) document . write ( m [ i ] [ j ] + " " ) ; document . write ( " " ) ; } return 0 ; } let m = [ [ 9 , 8 , 7 , 1 ] , [ 7 , 3 , 0 , 2 ] , [ 9 , 5 , 3 , 2 ] , [ 6 , 3 , 1 , 2 ] ] ; sortRowWise ( m ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let n = 3 function checkMarkov ( m ) { for ( let i = 0 ; i < n ; i ++ ) { let sum = 0 ; for ( let j = 0 ; j < n ; j ++ ) sum = sum + m [ i ] [ j ] ; if ( sum != 1 ) return false ; } return true ; } let m = [ [ 0 , 0 , 1 ] , [ 0.5 , 0 , 0.5 ] , [ 1 , 0 , 0 ] ] ; if ( checkMarkov ( m ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let N = 4 ; function isDiagonalMatrix ( mat ) { for ( let i = 0 ; i < N ; i ++ ) for ( let j = 0 ; j < N ; j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ; return true ; } let mat = [ [ 4 , 0 , 0 , 0 ] , [ 0 , 7 , 0 , 0 ] , [ 0 , 0 , 5 , 0 ] , [ 0 , 0 , 0 , 1 ] ] ; if ( isDiagonalMatrix ( mat ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let N = 4 ; function isScalarMatrix ( mat ) { for ( let i = 0 ; i < N ; i ++ ) for ( let j = 0 ; j < N ; j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ; for ( let i = 0 ; i < N - 1 ; i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ; return true ; } let mat = [ [ 2 , 0 , 0 , 0 ] , [ 0 , 2 , 0 , 0 ] , [ 0 , 0 , 2 , 0 ] , [ 0 , 0 , 0 , 2 ] ] ; if ( isScalarMatrix ( mat ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } function buildUtil ( In , post , inStrt , inEnd , postStrt , postEnd ) { if ( inStrt > inEnd ) return null ; let node = new Node ( post [ postEnd ] ) ; if ( inStrt == inEnd ) return node ; let iIndex = search ( In , inStrt , inEnd , node . data ) ; node . left = buildUtil ( In , post , inStrt , iIndex - 1 , postStrt , postStrt - inStrt + iIndex - 1 ) ; node . right = buildUtil ( In , post , iIndex + 1 , inEnd , postEnd - inEnd + iIndex , postEnd - 1 ) ; return node ; } function search ( arr , strt , end , value ) { let i ; for ( i = strt ; i <= end ; i ++ ) { if ( arr [ i ] == value ) break ; } return i ; } function preOrder ( node ) { if ( node == null ) return ; document . write ( node . data + " " ) ; preOrder ( node . left ) ; preOrder ( node . right ) ; } let In = [ 4 , 8 , 2 , 5 , 1 , 6 , 3 , 7 ] ; let post = [ 8 , 4 , 5 , 2 , 6 , 7 , 3 , 1 ] ; let n = In . length ; let root = buildUtil ( In , post , 0 , n - 1 , 0 , n - 1 ) ; document . write ( " " ) ; preOrder ( root ) ;

Index/key variables: i, postEnd
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
var SIZE = 10 ; function subCount ( arr , n , k ) { var mod = Array ( k ) . fill ( 0 ) ; var cumSum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { cumSum += arr [ i ] ; mod [ ( ( cumSum % k ) + k ) % k ] ++ ; } var result = 0 ; for ( var i = 0 ; i < k ; i ++ ) if ( mod [ i ] > 1 ) result += ( mod [ i ] * ( mod [ i ] - 1 ) ) / 2 ; result += mod [ 0 ] ; return result ; } function countSubmatrix ( mat , n , k ) { var tot_count = 0 ; var left , right , i ; var temp = Array ( n ) ; for ( left = 0 ; left < n ; left ++ ) { temp = Array ( n ) . fill ( 0 ) ; for ( right = left ; right < n ; right ++ ) { for ( i = 0 ; i < n ; ++ i ) temp [ i ] += mat [ i ] [ right ] ; tot_count += subCount ( temp , n , k ) ; } } return tot_count ; } var mat = [ [ 5 , - 1 , 6 ] , [ - 2 , 3 , 8 ] , [ 7 , 4 , - 9 ] ] ; var n = 3 , k = 4 ; document . write ( " " + countSubmatrix ( mat , n , k ) ) ;

Index/key variables: i, right
Accumulator variables: cumSum, i, left, result, right, tot_count
Iterator variables: i, left, right
Javascript program:
function findMinOpeartion ( matrix , n ) { let sumRow = new Array ( n ) ; let sumCol = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { sumRow [ i ] = 0 ; sumCol [ i ] = 0 ; } for ( let i = 0 ; i < n ; ++ i ) for ( let j = 0 ; j < n ; ++ j ) { sumRow [ i ] += matrix [ i ] [ j ] ; sumCol [ j ] += matrix [ i ] [ j ] ; } let maxSum = 0 ; for ( let i = 0 ; i < n ; ++ i ) { maxSum = Math . max ( maxSum , sumRow [ i ] ) ; maxSum = Math . max ( maxSum , sumCol [ i ] ) ; } let count = 0 ; for ( let i = 0 , j = 0 ; i < n && j < n ; ) { let diff = Math . min ( maxSum - sumRow [ i ] , maxSum - sumCol [ j ] ) ; matrix [ i ] [ j ] += diff ; sumRow [ i ] += diff ; sumCol [ j ] += diff ; count += diff ; if ( sumRow [ i ] == maxSum ) ++ i ; if ( sumCol [ j ] == maxSum ) ++ j ; } return count ; } function printMatrix ( matrix , n ) { for ( let i = 0 ; i < n ; ++ i ) { for ( let j = 0 ; j < n ; ++ j ) document . write ( matrix [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } let matrix = [ [ 1 , 2 ] , [ 3 , 4 ] ] ; document . write ( findMinOpeartion ( matrix , 2 ) + " " ) ; printMatrix ( matrix , 2 ) ;

Index/key variables: i, j
Accumulator variables: count, i
Iterator variables: i, j
Javascript program:
function ZigZag ( rows , columns , numbers ) { let k = 0 ; let arr = new Array ( rows ) ; for ( let i = 0 ; i < rows ; i ++ ) { arr [ i ] = new Array ( rows ) ; for ( let j = 0 ; j < columns ; j ++ ) { arr [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < rows ; i ++ ) { if ( i % 2 == 0 ) { for ( let j = 0 ; j < columns && numbers [ k ] > 0 ; j ++ ) { arr [ i ] [ j ] = k + 1 ; numbers [ k ] -- ; if ( numbers [ k ] == 0 ) k ++ ; } } else { for ( let j = columns - 1 ; j >= 0 && numbers [ k ] > 0 ; j -- ) { arr [ i ] [ j ] = k + 1 ; numbers [ k ] -- ; if ( numbers [ k ] == 0 ) k ++ ; } } } for ( let i = 0 ; i < rows ; i ++ ) { for ( let j = 0 ; j < columns ; j ++ ) document . write ( arr [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } let rows = 4 ; let columns = 5 ; let Numbers = [ 3 , 4 , 2 , 2 , 3 , 1 , 5 ] ; ZigZag ( rows , columns , Numbers ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j
Javascript program:
function numberofPosition ( n , k , x , y , obstPosx , obstPosy ) { let d11 , d12 , d21 , d22 , r1 , r2 , c1 , c2 ; d11 = Math . min ( x - 1 , y - 1 ) ; d12 = Math . min ( n - x , n - y ) ; d21 = Math . min ( n - x , y - 1 ) ; d22 = Math . min ( x - 1 , n - y ) ; r1 = y - 1 ; r2 = n - y ; c1 = x - 1 ; c2 = n - x ; for ( let i = 0 ; i < k ; i ++ ) { if ( x > obstPosx [ i ] && y > obstPosy [ i ] && x - obstPosx [ i ] == y - obstPosy [ i ] ) d11 = Math . min ( d11 , x - obstPosx [ i ] - 1 ) ; if ( obstPosx [ i ] > x && obstPosy [ i ] > y && obstPosx [ i ] - x == obstPosy [ i ] - y ) d12 = Math . min ( d12 , obstPosx [ i ] - x - 1 ) ; if ( obstPosx [ i ] > x && y > obstPosy [ i ] && obstPosx [ i ] - x == y - obstPosy [ i ] ) d21 = Math . min ( d21 , obstPosx [ i ] - x - 1 ) ; if ( x > obstPosx [ i ] && obstPosy [ i ] > y && x - obstPosx [ i ] == obstPosy [ i ] - y ) d22 = Math . min ( d22 , x - obstPosx [ i ] - 1 ) ; if ( x == obstPosx [ i ] && obstPosy [ i ] < y ) r1 = min ( r1 , y - obstPosy [ i ] - 1 ) ; if ( x == obstPosx [ i ] && obstPosy [ i ] > y ) r2 = Math . min ( r2 , obstPosy [ i ] - y - 1 ) ; if ( y == obstPosy [ i ] && obstPosx [ i ] < x ) c1 = Math . min ( c1 , x - obstPosx [ i ] - 1 ) ; if ( y == obstPosy [ i ] && obstPosx [ i ] > x ) c2 = Math . min ( c2 , obstPosx [ i ] - x - 1 ) ; } return d11 + d12 + d21 + d22 + r1 + r2 + c1 + c2 ; } let n = 8 ; let k = 1 ; let Qposx = 4 ; let Qposy = 4 ; let obstPosx = [ 3 ] ; let obstPosy = [ 5 ] ; document . write ( numberofPosition ( n , k , Qposx , Qposy , obstPosx , obstPosy ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let n = 5 ; function FindMaxProduct ( arr , n ) { let max = 0 , result ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( ( j - 3 ) >= 0 ) { result = arr [ i ] [ j ] * arr [ i ] [ j - 1 ] * arr [ i ] [ j - 2 ] * arr [ i ] [ j - 3 ] ; if ( max < result ) max = result ; } if ( ( i - 3 ) >= 0 ) { result = arr [ i ] [ j ] * arr [ i - 1 ] [ j ] * arr [ i - 2 ] [ j ] * arr [ i - 3 ] [ j ] ; if ( max < result ) max = result ; } if ( ( i - 3 ) >= 0 && ( j - 3 ) >= 0 ) { result = arr [ i ] [ j ] * arr [ i - 1 ] [ j - 1 ] * arr [ i - 2 ] [ j - 2 ] * arr [ i - 3 ] [ j - 3 ] ; if ( max < result ) max = result ; } if ( ( i - 3 ) >= 0 && ( j - 1 ) <= 0 ) { result = arr [ i ] [ j ] * arr [ i - 1 ] [ j + 1 ] * arr [ i - 2 ] [ j + 2 ] * arr [ i - 3 ] [ j + 3 ] ; if ( max < result ) max = result ; } } } return max ; } let arr = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 6 , 7 , 8 , 9 , 1 ] , [ 2 , 3 , 4 , 5 , 6 ] , [ 7 , 8 , 9 , 1 , 0 ] , [ 9 , 6 , 4 , 2 , 3 ] ] ; document . write ( FindMaxProduct ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxPro ( a , n , m , k ) { let maxi = 1 , mp = 1 ; for ( let i = 0 ; i < n ; ++ i ) { let wp = 1 ; for ( let l = 0 ; l < k ; ++ l ) { wp *= a [ i ] [ l ] ; } mp = wp ; for ( let j = k ; j < m ; ++ j ) { wp = wp * a [ i ] [ j ] / a [ i ] [ j - k ] ; maxi = Math . max ( maxi , Math . max ( mp , wp ) ) ; } } return maxi ; } let n = 6 , m = 5 , k = 4 ; let a = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 6 , 7 , 8 , 9 , 1 ] , [ 2 , 3 , 4 , 5 , 6 ] , [ 7 , 8 , 9 , 1 , 0 ] , [ 9 , 6 , 4 , 2 , 3 ] , [ 1 , 1 , 2 , 1 , 1 ] ] let maxpro = maxPro ( a , n , m , k ) ; document . write ( maxpro ) ;

Index/key variables: i, j, l
Accumulator variables: wp
Iterator variables: i, j, l
Javascript program:
/ *JavaScript Program to find minimum flip required to make Binary Matrix symmetric along main diagonal function minimumflip ( mat , n ) { let transpose = new Array ( n ) ; for ( var i = 0 ; i < transpose . length ; i ++ ) { transpose [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < n ; j ++ ) transpose [ i ] [ j ] = mat [ j ] [ i ] ; let flip = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < n ; j ++ ) if ( transpose [ i ] [ j ] != mat [ i ] [ j ] ) flip ++ ; return flip / 2 ; } let n = 3 ; let mat = [ [ 0 , 0 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 0 , 0 ] ] ; document . write ( minimumflip ( mat , n ) ) ;

Index/key variables: i, j
Accumulator variables: flip, i, j
Iterator variables: i, j
Javascript program:
function minimumflip ( mat , n ) { let flip = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < i ; j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ; return flip ; } let n = 3 ; let mat = [ [ 0 , 0 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 0 , 0 ] ] ; document . write ( minimumflip ( mat , n ) ) ;

Index/key variables: i, j
Accumulator variables: flip, i, j
Iterator variables: i, j
Javascript program:
let MAX = 100 ; function freq ( ar , m , n ) { let even = 0 , odd = 0 ; for ( let i = 0 ; i < m ; ++ i ) { for ( let j = 0 ; j < n ; ++ j ) { if ( ( ar [ i ] [ j ] % 2 ) == 0 ) ++ even ; else ++ odd ; } } document . write ( " " + odd + " " ) ; document . write ( " " + even + " " ) ; } let m = 3 , n = 3 ; let array = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; freq ( array , m , n ) ;

Index/key variables: i, j
Iterator variables: i, j
Javascript program:
const MAX = 100 ; function HalfDiagonalSums ( mat , n ) { let diag1_left = 0 , diag1_right = 0 ; let diag2_left = 0 , diag2_right = 0 ; for ( let i = 0 , j = n - 1 ; i < n ; i ++ , j -- ) { if ( i < parseInt ( n / 2 ) ) { diag1_left += mat [ i ] [ i ] ; diag2_left += mat [ j ] [ i ] ; } else if ( i > parseInt ( n / 2 ) ) { diag1_right += mat [ i ] [ i ] ; diag2_right += mat [ j ] [ i ] ; } } return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ parseInt ( n / 2 ) ] [ parseInt ( n / 2 ) ] ) ; } let a = [ [ 2 , 9 , 1 , 4 , - 2 ] , [ 6 , 7 , 2 , 11 , 4 ] , [ 4 , 2 , 9 , 2 , 4 ] , [ 1 , 9 , 2 , 4 , 4 ] , [ 0 , 2 , 4 , 2 , 5 ] ] ; document . write ( HalfDiagonalSums ( a , 5 ) ? " " : " " ) ;

Index/key variables: i, j
Accumulator variables: diag1_left, diag1_right, diag2_left, diag2_right, i, j
Iterator variables: i
Javascript program:
function Identity ( num ) { var row ; var col ; for ( row = 0 ; row < num ; row ++ ) { for ( col = 0 ; col < num ; col ++ ) { if ( row == col ) document . write ( 1 + " " ) ; else document . write ( 0 + " " ) ; } document . write ( " " + " " ) ; } return 0 ; } size = 5 ; Identity ( size ) ;

Accumulator variables: col, row
Iterator variables: col, row
Javascript program:
let MAX = 100 ; function isIdentity ( mat , N ) { for ( let row = 0 ; row < N ; row ++ ) { for ( let col = 0 ; col < N ; col ++ ) { if ( row == col && mat [ row ] [ col ] != 1 ) return false ; else if ( row != col && mat [ row ] [ col ] != 0 ) return false ; } } return true ; } let N = 4 ; let mat = [ [ 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 0 , 0 , 0 , 1 ] ] ; if ( isIdentity ( mat , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: col, row
Accumulator variables: col, row
Iterator variables: col, row
Javascript program:
let MAX = 100 ; function imageSwap ( mat , n ) { let row = 0 ; for ( let j = 0 ; j < n ; j ++ ) { let s = [ ] ; let i = row , k = j ; while ( i < n && k >= 0 ) { s . push ( mat [ i ++ ] [ k -- ] ) ; } i = row ; k = j ; while ( i < n && k >= 0 ) { mat [ i ++ ] [ k -- ] = s [ s . length - 1 ] ; s . pop ( ) ; } } let column = n - 1 ; for ( let j = 1 ; j < n ; j ++ ) { let s = [ ] ; let i = j , k = column ; while ( i < n && k >= 0 ) { s . push ( mat [ i ++ ] [ k -- ] ) ; } i = j ; k = column ; while ( i < n && k >= 0 ) { mat [ i ++ ] [ k -- ] = s [ s . length - 1 ] ; s . pop ( ) ; } } } function printMatrix ( mat , n ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let mat = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; let n = 4 ; imageSwap ( mat , n ) ; printMatrix ( mat , n ) ;

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: i, j
Javascript program:
let MAX = 100 ; function imageSwap ( mat , n ) { for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j <= i ; j ++ ) mat [ i ] [ j ] = mat [ i ] [ j ] + mat [ j ] [ i ] - ( mat [ j ] [ i ] = mat [ i ] [ j ] ) ; } function printMatrix ( mat , n ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) document . write ( mat [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } let mat = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; let n = 4 ; imageSwap ( mat , n ) ; printMatrix ( mat , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function search ( mat , n , x ) { if ( n == 0 ) return - 1 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) if ( mat [ i ] [ j ] == x ) { document . write ( " " + i + " " + j + " " ) ; return 1 ; } } document . write ( " " ) ; return 0 ; } let mat = [ [ 10 , 20 , 30 , 40 ] , [ 15 , 25 , 35 , 45 ] , [ 27 , 29 , 37 , 48 ] , [ 32 , 33 , 39 , 50 ] ] ; search ( mat , 4 , 29 ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function search ( mat , n , x ) { let i = 0 , j = n - 1 ; while ( i < n && j >= 0 ) { if ( mat [ i ] [ j ] == x ) { document . write ( " " + i + " " + j ) ; return ; } if ( mat [ i ] [ j ] > x ) j -- ; else i ++ ; } document . write ( " " ) ; return ; } let mat = [ [ 10 , 20 , 30 , 40 ] , [ 15 , 25 , 35 , 45 ] , [ 27 , 29 , 37 , 48 ] , [ 32 , 33 , 39 , 50 ] ] ; search ( mat , 4 , 29 ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
function fill0X ( m , n ) { let i , k = 0 , l = 0 ; let r = m , c = n ; let a = new Array ( m ) ; for ( let i = 0 ; i < m ; i ++ ) { a [ i ] = new Array ( n ) ; } let x = ' ' ; while ( k < m && l < n ) { for ( i = l ; i < n ; ++ i ) { a [ k ] [ i ] = x ; } k ++ ; for ( i = k ; i < m ; ++ i ) { a [ i ] [ n - 1 ] = x ; } n -- ; if ( k < m ) { for ( i = n - 1 ; i >= l ; -- i ) a [ m - 1 ] [ i ] = x ; m -- ; } if ( l < n ) { for ( i = m - 1 ; i >= k ; -- i ) { a [ i ] [ l ] = x ; } l ++ ; } x = ( x == ' ' ) ? ' ' : ' ' ; } for ( i = 0 ; i < r ; i ++ ) { for ( let j = 0 ; j < c ; j ++ ) { document . write ( a [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } document . write ( " " ) ; fill0X ( 5 , 6 ) ; document . write ( " " ) ; fill0X ( 4 , 4 ) ; document . write ( " " ) ; fill0X ( 3 , 4 ) ;

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l, m, n
Iterator variables: i, j
Javascript program:
let SIZE = 100 ; function calculateEnergy ( mat , n ) { let i_des , j_des , q ; let tot_energy = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { q = Math . floor ( mat [ i ] [ j ] / n ) ; i_des = q ; j_des = mat [ i ] [ j ] - ( n * q ) ; tot_energy += Math . abs ( i_des - i ) + Math . abs ( j_des - j ) ; } } return tot_energy ; } let mat = [ [ 4 , 7 , 0 , 3 ] , [ 8 , 5 , 6 , 1 ] , [ 9 , 11 , 10 , 2 ] , [ 15 , 13 , 14 , 12 ] ] ; let n = 4 ; document . write ( " " + calculateEnergy ( mat , n ) + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j, tot_energy
Iterator variables: i, j