dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function isupper ( str ) { return str === str . toUpperCase ( ) ; } function minOperations ( str , n ) { var i , lastUpper = - 1 , firstLower = - 1 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( isupper ( str [ i ] ) ) { lastUpper = i ; break ; } } for ( i = 0 ; i < n ; i ++ ) { if ( islower ( str [ i ] ) ) { firstLower = i ; break ; } } if ( lastUpper === - 1 firstLower === - 1 ) return 0 ; var countUpper = 0 ; for ( i = firstLower ; i < n ; i ++ ) { if ( isupper ( str [ i ] ) ) { countUpper ++ ; } } var countLower = 0 ; for ( i = 0 ; i < lastUpper ; i ++ ) { if ( islower ( str [ i ] ) ) { countLower ++ ; } } return Math . min ( countLower , countUpper ) ; } var str = " " ; var n = str . length ; document . write ( minOperations ( str , n ) + " " ) ;

Index/key variables: i
Accumulator variables: countLower, countUpper, i
Iterator variables: i
Javascript program:
function Betrothed_Sum ( n ) { let Set = [ ] ; for ( let number_1 = 1 ; number_1 < n ; number_1 ++ ) { let sum_divisor_1 = 1 ; let i = 2 ; while ( i * i <= number_1 ) { if ( number_1 % i == 0 ) { sum_divisor_1 = sum_divisor_1 + i ; if ( i * i != number_1 ) sum_divisor_1 += parseInt ( number_1 / i ) ; } i ++ ; } if ( sum_divisor_1 > number_1 ) { let number_2 = sum_divisor_1 - 1 ; let sum_divisor_2 = 1 ; let j = 2 ; while ( j * j <= number_2 ) { if ( number_2 % j == 0 ) { sum_divisor_2 += j ; if ( j * j != number_2 ) sum_divisor_2 += parseInt ( number_2 / j ) ; } j = j + 1 ; } if ( ( sum_divisor_2 == number_1 + 1 ) && number_1 <= n && number_2 <= n ) { Set . push ( number_1 ) ; Set . push ( number_2 ) ; } } } let Summ = 0 ; for ( let i = 0 ; i < Set . length ; i ++ ) { if ( Set [ i ] <= n ) Summ += Set [ i ] ; } return Summ ; } let n = 78 ; document . write ( Betrothed_Sum ( n ) ) ;

Index/key variables: i
Accumulator variables: Summ, i, number_1, sum_divisor_1, sum_divisor_2
Iterator variables: i, number_1
Javascript program:
function rainDayProbability ( a , n ) { let count = 0 , m ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 1 ) count ++ ; } m = count / n ; return m ; } let a = [ 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 ] ; let n = a . length ; document . write ( rainDayProbability ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function Series ( n ) { let sums = 0.0 ; for ( let i = 1 ; i < n + 1 ; i ++ ) { ser = 1 / Math . pow ( i , i ) ; sums += ser ; } return sums ; } let n = 3 ; let res = Math . round ( Series ( n ) * 100000 ) / 100000 ; document . write ( res ) ;

Accumulator variables: i, sums
Iterator variables: i
Javascript program:
function lexicographicallyMaximum ( S , N ) { let M = new Map ( ) ; for ( let i = 0 ; i < N ; ++ i ) { if ( M . has ( S [ i ] ) ) M . set ( S [ i ] , M . get ( S [ i ] ) + 1 ) ; else M . set ( S [ i ] , 1 ) ; } let V = [ ] ; for ( let i = ' ' . charCodeAt ( ) ; i < ( ' ' . charCodeAt ( ) + Math . min ( N , 25 ) ) ; ++ i ) { if ( M . has ( String . fromCharCode ( i ) ) == false ) { V . push ( String . fromCharCode ( i ) ) ; } } let j = V . length - 1 ; for ( let i = 0 ; i < N ; ++ i ) { if ( S [ i ] . charCodeAt ( ) >= ( ' ' . charCodeAt ( ) + Math . min ( N , 25 ) ) || ( M . has ( S [ i ] ) && M . get ( S [ i ] ) > 1 ) ) { if ( V [ j ] . charCodeAt ( ) < S [ i ] . charCodeAt ( ) ) continue ; M . set ( S [ i ] , M . get ( S [ i ] ) - 1 ) ; S = S . substr ( 0 , i ) + V [ j ] + S . substr ( i + 1 ) ; j -- ; } if ( j < 0 ) break ; } let l = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { if ( l > j ) break ; if ( S [ i ] . charCodeAt ( ) >= ( ' ' . charCodeAt ( ) + Math . min ( N , 25 ) ) || M . has ( S [ i ] ) && M . get ( S [ i ] ) > 1 ) { M . set ( S [ i ] , M . get ( S [ i ] ) - 1 ) ; S = S . substr ( 0 , i ) + V [ l ] + S . substr ( i + 1 ) ; l ++ ; } } return S ; } let S = " " ; let N = S . length ; document . write ( lexicographicallyMaximum ( S , N ) ) ;

Index/key variables: i, j, l
Accumulator variables: i, j, l
Iterator variables: i
Javascript program:
function isConsistingSubarrayUtil ( arr , n ) { var mp = new Map ( ) ; for ( var i = 0 ; i < n ; ++ i ) { if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . set ( arr [ i ] , 1 ) ; } } var ans = false ; mp . forEach ( ( value , key ) => { if ( value > 1 ) { ans = true ; } } ) ; if ( ans ) return true ; return false ; } function isConsistingSubarray ( arr , N ) { if ( isConsistingSubarrayUtil ( arr , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var arr = [ 1 , 2 , 3 , 4 , 5 , 1 ] ; var N = arr . length ; isConsistingSubarray ( arr , N ) ;

Index/key variables: i
Iterator variables: i
Boolean variables: ans
Javascript program:
function createhashmap ( Max ) { var hashmap = new Set ( ) ; var curr = 1 ; var prev = 0 ; hashmap . add ( prev ) ; while ( curr <= Max ) { hashmap . add ( curr ) ; var temp = curr ; curr = curr + prev ; prev = temp ; } return hashmap ; } function SieveOfEratosthenes ( Max ) { var isPrime = Array ( Max + 1 ) . fill ( true ) ; isPrime [ 0 ] = false ; isPrime [ 1 ] = false ; for ( var p = 2 ; p * p <= Max ; p ++ ) { if ( isPrime [ p ] ) { for ( var i = p * p ; i <= Max ; i += p ) { isPrime [ i ] = false ; } } } return isPrime ; } function cntFibonacciPrime ( arr , N ) { var Max = arr [ 0 ] ; for ( var i = 1 ; i < N ; i ++ ) { Max = Math . max ( Max , arr [ i ] ) ; } var isPrime = SieveOfEratosthenes ( Max ) ; var hashmap = createhashmap ( Max ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) continue ; if ( hashmap . has ( arr [ i ] ) && ! isPrime [ arr [ i ] ] ) { document . write ( arr [ i ] + " " ) ; } } } var arr = [ 13 , 55 , 7 , 3 , 5 , 21 , 233 , 144 , 89 ] ; var N = arr . length ; cntFibonacciPrime ( arr , N ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function key ( N ) { let num = " " + N . toString ( ) ; let ans = 0 ; let j = 0 ; for ( j = 0 ; j < num . length ; j ++ ) { if ( ( num [ j ] . charCodeAt ( ) - 48 ) % 2 == 0 ) { let add = 0 ; let i ; for ( i = j ; j < num . length ; j ++ ) { add += num [ j ] . charCodeAt ( ) - 48 ; if ( add % 2 == 1 ) break ; } if ( add == 0 ) { ans *= 10 ; } else { let digit = Math . floor ( Math . log10 ( add ) + 1 ) ; ans *= parseInt ( Math . pow ( 10 , digit ) , 10 ) ; ans += add ; } i = j ; } else { let add = 0 ; let i ; for ( i = j ; j < num . length ; j ++ ) { add += num [ j ] . charCodeAt ( ) - 48 ; if ( add % 2 == 0 ) { break ; } } if ( add == 0 ) { ans *= 10 ; } else { let digit = Math . floor ( Math . log10 ( add ) + 1 ) ; ans *= parseInt ( Math . pow ( 10 , digit ) , 10 ) ; ans += add ; } i = j ; } } if ( j + 1 >= num . length ) { return ans ; } else { return ans += num [ num . length - 1 ] . charCodeAt ( ) - 48 ; } } let N = 1667848271 ; document . write ( key ( N ) ) ;

Index/key variables: j
Accumulator variables: add, ans, j
Iterator variables: i, j
Javascript program:
function sentinelSearch ( arr , n , key ) { var last = arr [ n - 1 ] ; arr [ n - 1 ] = key ; var i = 0 ; while ( arr [ i ] != key ) i ++ ; arr [ n - 1 ] = last ; if ( ( i < n - 1 ) || ( arr [ n - 1 ] == key ) ) document . write ( key + " " + i ) ; else document . write ( " " ) ; } var arr = [ 10 , 20 , 180 , 30 , 60 , 50 , 110 , 100 , 70 ] ; var n = arr . length ; var key = 180 ; sentinelSearch ( arr , n , key ) ;

Index/key variables: i
Accumulator variables: i
Javascript program:
function maximum_middle_value ( n , k , arr ) { let ans = - 1 ; let low = Math . floor ( ( n + 1 - k ) / 2 ) ; let high = Math . floor ( ( ( n + 1 - k ) / 2 ) + k ) ; for ( let i = low ; i <= high ; i ++ ) { ans = Math . max ( ans , arr [ i - 1 ] ) ; } return ans ; } let n = 5 , k = 2 ; let arr = [ 9 , 5 , 3 , 7 , 10 ] ; document . write ( maximum_middle_value ( n , k , arr ) + " " ) ; n = 9 ; k = 3 ; let arr1 = [ 2 , 4 , 3 , 9 , 5 , 8 , 7 , 6 , 10 ] ; document . write ( maximum_middle_value ( n , k , arr1 ) + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function ternarySearch ( l , r , key , ar ) { if ( r >= l ) { let mid1 = l + parseInt ( ( r - l ) / 3 , 10 ) ; let mid2 = r - parseInt ( ( r - l ) / 3 , 10 ) ; if ( ar [ mid1 ] == key ) { return mid1 ; } if ( ar [ mid2 ] == key ) { return mid2 ; } if ( key < ar [ mid1 ] ) { return ternarySearch ( l , mid1 - 1 , key , ar ) ; } else if ( key > ar [ mid2 ] ) { return ternarySearch ( mid2 + 1 , r , key , ar ) ; } else { return ternarySearch ( mid1 + 1 , mid2 - 1 , key , ar ) ; } } return - 1 ; } let l , r , p , key ; let ar = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ; l = 0 ; r = 9 ; key = 5 ; p = ternarySearch ( l , r , key , ar ) ; document . write ( " " + key + " " + p + " " ) ; key = 50 ; p = ternarySearch ( l , r , key , ar ) ; document . write ( " " + key + " " + p ) ;

Index/key variables: mid1, mid2
Javascript program:
function findmin ( p , n ) { let a = 0 , b = 0 , c = 0 , d = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( p [ i ] [ 0 ] <= 0 ) a ++ ; else if ( p [ i ] [ 0 ] >= 0 ) b ++ ; if ( p [ i ] [ 1 ] >= 0 ) c ++ ; else if ( p [ i ] [ 1 ] <= 0 ) d ++ ; } return Math . min ( Math . min ( a , b ) , Math . min ( c , d ) ) ; } let p = [ [ 1 , 1 ] , [ 2 , 2 ] , [ - 1 , - 1 ] , [ - 2 , 2 ] ] let n = p . length ; document . write ( findmin ( p , n ) ) ;

Index/key variables: i
Accumulator variables: a, b, c, d, i
Iterator variables: i
Javascript program:
function maxOps ( a , b , c ) { let arr = [ a , b , c ] ; let count = 0 ; while ( 1 ) { arr . sort ( ) ; if ( ! arr [ 0 ] && ! arr [ 1 ] ) break ; arr [ 1 ] -= 1 ; arr [ 2 ] -= 1 ; count += 1 ; } document . write ( count ) ; } let a = 4 , b = 3 , c = 2 ; maxOps ( a , b , c ) ;

Accumulator variables: count
Javascript program:
var MAX = 26 ; function getSortedString ( s , n ) { var lower = Array ( MAX ) . fill ( 0 ) ; var upper = Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( ( s [ i ] ) == s [ i ] . toLowerCase ( ) ) lower [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; else if ( s [ i ] = s [ i ] . toUpperCase ( ) ) upper [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } var i = 0 , j = 0 ; while ( i < MAX && lower [ i ] == 0 ) i ++ ; while ( j < MAX && upper [ j ] == 0 ) j ++ ; for ( var k = 0 ; k < n ; k ++ ) { if ( s [ k ] == s [ k ] . toLowerCase ( ) ) { while ( lower [ i ] == 0 ) i ++ ; s [ k ] = String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; lower [ i ] -- ; } else if ( s [ k ] == s [ k ] . toUpperCase ( ) ) { while ( upper [ j ] == 0 ) j ++ ; s [ k ] = String . fromCharCode ( j + ' ' . charCodeAt ( 0 ) ) ; upper [ j ] -- ; } } return s . join ( ' ' ) ; } var s = " " ; var n = s . length ; document . write ( getSortedString ( s . split ( ' ' ) , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, k
Javascript program:
let SIZE = 26 ; function printCharWithFreq ( str ) { let n = str . length ; let freq = new Array ( SIZE ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < n ; i ++ ) { if ( freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] != 0 ) { document . write ( str [ i ] ) ; document . write ( freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] + " " ) ; freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = 0 ; } } } let str = " " ; printCharWithFreq ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var s = [ " " , " " , " " , " " , " " , " " ] ; var ans = " " ; for ( var i = 5 ; i >= 0 ; i -- ) { ans += s [ i ] + " " ; } document . write ( " " + " " ) ; document . write ( ans . slice ( 0 , ans . length - 1 ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function SieveOfEratosthenes ( prime , n ) { for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } function segregatePrimeNonPrime ( prime , arr , N ) { SieveOfEratosthenes ( prime , 10000000 ) ; let left = 0 , right = N - 1 ; while ( left < right ) { while ( prime [ arr [ left ] ] ) left ++ ; while ( ! prime [ arr [ right ] ] ) right -- ; if ( left < right ) { let temp = arr [ left ] ; arr [ left ] = arr [ right ] ; arr [ right ] = temp ; left ++ ; right -- ; } } for ( let i = 0 ; i < N ; i ++ ) document . write ( arr [ i ] + " " ) ; } let prime = Array . from ( { length : 10000001 } , ( _ , i ) => true ) ; let arr = [ 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 ] ; let N = arr . length ; segregatePrimeNonPrime ( prime , arr , N ) ;

Index/key variables: i, left, p, right
Accumulator variables: i, left, p, right
Iterator variables: i, p
Javascript program:
function findDepthRec ( tree , n , index ) { if ( index >= n tree [ index ] == ' ' ) return 0 ; index ++ ; let left = findDepthRec ( tree , n , index ) ; index ++ ; let right = findDepthRec ( tree , n , index ) ; return Math . max ( left , right ) + 1 ; } function findDepth ( tree , n ) { let index = 0 ; return ( findDepthRec ( tree , n , index ) ) ; } let tree = " " . split ( ' ' ) ; let n = tree . length ; document . write ( findDepth ( tree , n ) ) ;

Index/key variables: index
Accumulator variables: index
Javascript program:
class Node { constructor ( ) { this . key = 0 ; this . left = null , this . right = null ; } } function newNode ( item ) { var temp = new Node ( ) ; temp . key = item ; temp . left = null ; temp . right = null ; return temp ; } function insert ( node , key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insert ( node . left , key ) ; else if ( key > node . key ) node . right = insert ( node . right , key ) ; return node ; } function findMaxforN ( root , N ) { if ( root == null ) return - 1 ; if ( root . key == N ) return N ; else if ( root . key < N ) { var k = findMaxforN ( root . right , N ) ; if ( k == - 1 ) return root . key ; else return k ; } else if ( root . key > N ) return findMaxforN ( root . left , N ) ; return - 1 ; } var N = 4 ; var root = null ; root = insert ( root , 25 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 12 ) ; insert ( root , 9 ) ; insert ( root , 21 ) ; insert ( root , 19 ) ; insert ( root , 25 ) ; document . write ( findMaxforN ( root , N ) ) ;

Class/struct names: Node
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . left = null ; this . right = null ; } } function createNode ( x ) { var p = new Node ( ) ; p . data = x ; p . left = p . right = null ; return p ; } function insertNode ( root , x ) { var p = root , q = null ; while ( p != null ) { q = p ; if ( p . data < x ) p = p . right ; else p = p . left ; } if ( q == null ) p = createNode ( x ) ; else { if ( q . data < x ) q . right = createNode ( x ) ; else q . left = createNode ( x ) ; } } function maxelpath ( q , x ) { var p = q ; var mx = - 1 ; while ( p . data != x ) { if ( p . data > x ) { mx = Math . max ( mx , p . data ) ; p = p . left ; } else { mx = Math . max ( mx , p . data ) ; p = p . right ; } } return Math . max ( mx , x ) ; } function maximumElement ( root , x , y ) { var p = root ; while ( ( x < p . data && y < p . data ) || ( x > p . data && y > p . data ) ) { if ( x < p . data && y < p . data ) p = p . left ; else if ( x > p . data && y > p . data ) p = p . right ; } return Math . max ( maxelpath ( p , x ) , maxelpath ( p , y ) ) ; } var arr = [ 18 , 36 , 9 , 6 , 12 , 10 , 1 , 8 ] ; var a = 1 , b = 10 ; var n = arr . length ; var root = createNode ( arr [ 0 ] ) ; for ( i = 1 ; i < n ; i ++ ) insertNode ( root , arr [ i ] ) ; document . write ( maximumElement ( root , a , b ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . left = null , this . right = null ; this . info = 0 ; this . lthread = false ; this . rthread = false ; } } function insert ( root , ikey ) { var ptr = root ; var par = null ; while ( ptr != null ) { if ( ikey == ( ptr . info ) ) { document . write ( " " ) ; return root ; } par = ptr ; if ( ikey < ptr . info ) { if ( ptr . lthread == false ) ptr = ptr . left ; else break ; } else { if ( ptr . rthread == false ) ptr = ptr . right ; else break ; } } var tmp = new Node ( ) ; tmp . info = ikey ; tmp . lthread = true ; tmp . rthread = true ; if ( par == null ) { root = tmp ; tmp . left = null ; tmp . right = null ; } else if ( ikey < ( par . info ) ) { tmp . left = par . left ; tmp . right = par ; par . lthread = false ; par . left = tmp ; } else { tmp . left = par ; tmp . right = par . right ; par . rthread = false ; par . right = tmp ; } return root ; } function inorderSuccessor ( ptr ) { if ( ptr . rthread == true ) return ptr . right ; ptr = ptr . right ; while ( ptr . lthread == false ) ptr = ptr . left ; return ptr ; } function inorder ( root ) { if ( root == null ) document . write ( " " ) ; var ptr = root ; while ( ptr . lthread == false ) ptr = ptr . left ; while ( ptr != null ) { document . write ( ptr . info + " " ) ; ptr = inorderSuccessor ( ptr ) ; } } var root = null ; root = insert ( root , 20 ) ; root = insert ( root , 10 ) ; root = insert ( root , 30 ) ; root = insert ( root , 5 ) ; root = insert ( root , 16 ) ; root = insert ( root , 14 ) ; root = insert ( root , 17 ) ; root = insert ( root , 13 ) ; inorder ( root ) ;

Boolean variables: lthread, rthread
Class/struct names: Node
Javascript program:
class Node { constructor ( ) { this . left = null , this . right = null ; this . info = 0 ; this . lthread = false ; this . rthread = false ; } }

Boolean variables: lthread, rthread
Class/struct names: Node
Javascript program:
function checkHV ( arr , N , M ) { let horizontal = true ; let vertical = true ; for ( let i = 0 , k = N - 1 ; i < parseInt ( N / 2 , 10 ) ; i ++ , k -- ) { for ( let j = 0 ; j < M ; j ++ ) { if ( arr [ i ] [ j ] != arr [ k ] [ j ] ) { horizontal = false ; break ; } } } for ( let i = 0 , k = M - 1 ; i < parseInt ( M / 2 , 10 ) ; i ++ , k -- ) { for ( let j = 0 ; j < N ; j ++ ) { if ( arr [ i ] [ j ] != arr [ k ] [ j ] ) { horizontal = false ; break ; } } } if ( ! horizontal && ! vertical ) document . write ( " " ) ; else if ( horizontal && ! vertical ) document . write ( " " ) ; else if ( vertical && ! horizontal ) document . write ( " " ) ; else document . write ( " " ) ; } let mat = [ [ 1 , 0 , 1 ] , [ 0 , 0 , 0 ] , [ 1 , 0 , 1 ] ] ; checkHV ( mat , 3 , 3 ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j
Boolean variables: horizontal, vertical
Javascript program:
let R = 3 ; let C = 4 ; function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function replacematrix ( mat , n , m ) { let rgcd = new Array ( R ) ; rgcd . fill ( 0 ) ; let cgcd = new Array ( C ) ; cgcd . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { rgcd [ i ] = gcd ( rgcd [ i ] , mat [ i ] [ j ] ) ; cgcd [ j ] = gcd ( cgcd [ j ] , mat [ i ] [ j ] ) ; } } for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < m ; j ++ ) mat [ i ] [ j ] = Math . max ( rgcd [ i ] , cgcd [ j ] ) ; } let m = [ [ 1 , 2 , 3 , 3 ] , [ 4 , 5 , 6 , 6 ] , [ 7 , 8 , 9 , 9 ] ] ; replacematrix ( m , R , C ) ; for ( let i = 0 ; i < R ; i ++ ) { for ( let j = 0 ; j < C ; j ++ ) document . write ( m [ i ] [ j ] + " " ) ; document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let N = 4 ; function add ( A , B , C ) { let i , j ; for ( i = 0 ; i < N ; i ++ ) for ( j = 0 ; j < N ; j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ; } let A = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ] ; let B = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ] ; let C = new Array ( N ) ; for ( let k = 0 ; k < N ; k ++ ) C [ k ] = new Array ( N ) ; let i , j ; add ( A , B , C ) ; document . write ( " " ) ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) document . write ( C [ i ] [ j ] + " " ) ; document . write ( " " ) ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
var N = 4 ; function subtract ( A , B , C ) { var i , j ; for ( i = 0 ; i < N ; i ++ ) for ( j = 0 ; j < N ; j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ; } var A = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ] ; var B = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ] ; var C = Array . from ( Array ( N ) , ( ) => Array ( N ) ) ; var i , j ; subtract ( A , B , C ) ; document . write ( " " + " " ) ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) document . write ( C [ i ] [ j ] + " " ) ; document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function linearSearch ( arr , n ) { let i ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == i ) return i ; } return - 1 ; } let arr = [ - 10 , - 1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 ] ; let n = arr . length ; document . write ( " " + linearSearch ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function binarySearch ( arr , low , high ) { if ( high >= low ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( mid == arr [ mid ] ) return mid ; if ( mid > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high ) ; else return binarySearch ( arr , low , ( mid - 1 ) ) ; } return - 1 ; } let arr = [ - 10 , - 1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 ] ; let n = arr . length ; document . write ( " " + binarySearch ( arr , 0 , n - 1 ) ) ;

Index/key variables: mid
Javascript program:
function maxTripletSum ( arr , n ) { let sum = - 1000000 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) for ( let k = j + 1 ; k < n ; k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ; return sum ; } let arr = [ 1 , 0 , 8 , 6 , 4 , 2 ] ; let n = arr . length ; document . write ( maxTripletSum ( arr , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function maxTripletSum ( arr , n ) { let maxA = Number . MIN_SAFE_INTEGER ; let maxB = Number . MIN_SAFE_INTEGER ; let maxC = Number . MIN_SAFE_INTEGER ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > maxA ) { maxC = maxB ; maxB = maxA ; maxA = arr [ i ] ; } else if ( arr [ i ] > maxB ) { maxC = maxB ; maxB = arr [ i ] ; } else if ( arr [ i ] > maxC ) maxC = arr [ i ] ; } return ( maxA + maxB + maxC ) ; } let arr = [ 1 , 0 , 8 , 6 , 4 , 2 ] ; let n = arr . length ; document . write ( maxTripletSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function search ( arr , n , x ) { let i ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == x ) return i ; return - 1 ; } let arr = [ 2 , 3 , 4 , 10 , 40 ] ; let x = 10 ; let n = arr . length ; let result = search ( arr , n , x ) ; ( result == - 1 ) ? document . write ( " " ) : document . write ( " " + result ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function search ( arr , search_Element ) { let left = 0 ; let length = arr . length ; let right = length - 1 ; let position = - 1 ; for ( left = 0 ; left <= right ; ) { if ( arr [ left ] == search_Element ) { position = left ; document . write ( " " + ( position + 1 ) + " " + ( left + 1 ) + " " ) ; break ; } if ( arr [ right ] == search_Element ) { position = right ; document . write ( " " + ( position + 1 ) + " " + ( length - right ) + " " ) ; break ; } left ++ ; right -- ; } if ( position == - 1 ) document . write ( " " + left + " " ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let search_element = 5 ; search ( arr , search_element ) ;

Index/key variables: left, right
Accumulator variables: left, right
Iterator variables: left