dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function checkIsHP ( arr ) { let n = arr . length ; if ( n == 1 ) { return true ; } let rec = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { rec . push ( ( 1 / arr [ i ] ) ) ; } rec . sort ( ( a , b ) => a - b ) ; let d = ( rec [ 1 ] ) - ( rec [ 0 ] ) ; for ( let i = 2 ; i < n ; i ++ ) { if ( rec [ i ] - rec [ i - 1 ] != d ) { return false ; } } return true ; } let arr = [ 1 / 5 , 1 / 10 , 1 / 15 , 1 / 20 , 1 / 25 ] ; if ( checkIsHP ( arr ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printAMeans ( A , B , N ) { let d = ( B - A ) / ( N + 1 ) ; for ( let i = 1 ; i <= N ; i ++ ) document . write ( ( A + i * d ) + " " ) ; } let A = 20 , B = 32 , N = 5 ; printAMeans ( A , B , N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function primeFactors ( n ) { while ( n % 2 == 0 ) { document . write ( 2 + " " ) ; n = Math . floor ( n / 2 ) ; } for ( let i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { document . write ( i + " " ) ; n = Math . floor ( n / i ) ; } } if ( n > 2 ) document . write ( n + " " ) ; } let n = 315 ; primeFactors ( n ) ;

Iterator variables: i
Javascript program:
function CheckArray ( arr , n ) { let prod = 1 ; for ( let i = 0 ; i < n ; ++ i ) prod *= arr [ i ] ; for ( let i = 0 ; i < n ; ++ i ) if ( arr [ i ] == prod / arr [ i ] ) return true ; return false ; } let arr = [ 1 , 2 , 12 , 3 , 2 ] ; let n = arr . length ; if ( CheckArray ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: prod
Iterator variables: i
Javascript program:
function sum ( a , b ) { var sum = 0 ; for ( var i = 1 ; i <= Math . min ( a , b ) ; i ++ ) if ( a % i == 0 && b % i == 0 ) sum += i ; return sum ; } var A = 10 , B = 15 ; document . write ( " " + sum ( A , B ) + " " ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findgcd ( a , b ) { if ( b == 0 ) return a ; return findgcd ( b , a % b ) ; } function minimumCuts ( a , n ) { a . sort ( ) ; var gcd = a [ 1 ] - a [ 0 ] ; var s = gcd ; for ( i = 2 ; i < n ; i ++ ) { gcd = findgcd ( gcd , a [ i ] - a [ i - 1 ] ) ; s += a [ i ] - a [ i - 1 ] ; } if ( 360 - s > 0 ) gcd = findgcd ( gcd , 360 - s ) ; return ( 360 / gcd ) - n ; } var arr = [ 30 , 60 , 180 ] ; var n = arr . length ; document . write ( minimumCuts ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Javascript program:
let MAXN = 100001 ; let spf = new Array ( MAXN ) ; for ( let i = 0 ; i < MAXN ; i ++ ) { spf [ i ] = 0 ; } function sieve ( ) { spf [ 1 ] = 1 ; for ( let i = 2 ; i < MAXN ; i ++ ) spf [ i ] = i ; for ( let i = 4 ; i < MAXN ; i += 2 ) spf [ i ] = 2 ; for ( let i = 3 ; i * i < MAXN ; i ++ ) { if ( spf [ i ] == i ) { for ( let j = i * i ; j < MAXN ; j += i ) if ( spf [ j ] == j ) spf [ j ] = i ; } } } function getFactorization ( x ) { let ret = [ ] ; while ( x != 1 ) { let temp = spf [ x ] ; ret . push ( temp ) ; while ( x % temp == 0 ) x = Math . floor ( x / temp ) ; } return ret ; } function maxElement ( A , n ) { sieve ( ) ; let m = new Map ( ) ; for ( let j = 0 ; j < n ; ++ j ) { let p = getFactorization ( A [ j ] ) ; for ( let i = 0 ; i < p . length ; i ++ ) m . set ( p [ i ] , m . get ( p [ i ] ) == null ? 0 : m . get ( p [ i ] ) + 1 ) ; } let cnt = 0 , ans = 10000000 ; for ( let [ key , value ] of m . entries ( ) ) { if ( value >= cnt ) { cnt = value ; if ( ans > key ) ans = key ; else ans = ans ; } } return ans ; } let A = [ 2 , 5 , 10 ] ; let n = A . length ; document . write ( maxElement ( A , n ) ) ;

Index/key variables: i, j, x
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function compositeProduct ( arr , n ) { let max_val = arr . sort ( ( A , B ) => B - A ) [ 0 ] ; let prime = new Array ( max_val + 1 ) . fill ( true ) ; prime [ 0 ] = true ; prime [ 1 ] = true ; for ( let p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } let product = 1 ; for ( let i = 0 ; i < n ; i ++ ) if ( ! prime [ arr [ i ] ] ) { product *= arr [ i ] ; } return product ; } let arr = new Array ( 2 , 3 , 4 , 5 , 6 , 7 ) ; let n = arr . length ; document . write ( compositeProduct ( arr , n ) ) ;

Index/key variables: i, p
Accumulator variables: i, p, product
Iterator variables: i, p
Javascript program:
function sum_odd ( n ) { let sum = 0 , pos = 1 ; while ( n ) { if ( pos % 2 == 1 ) sum += n % 10 ; n = Math . floor ( n / 10 ) ; pos ++ ; } return sum ; } function check_prime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } let n = 223 ; let sum = sum_odd ( n ) ; if ( check_prime ( sum ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Accumulator variables: pos, sum
Iterator variables: i
Javascript program:
function reverseNum ( x ) { let s = x . toString ( ) ; let str = " " ; for ( let i = s . length - 1 ; i >= 0 ; i -- ) { str = str + s [ i ] ; } let rev = parseInt ( str ) ; return rev ; } function isMysteryNumber ( n ) { for ( let i = 1 ; i <= Math . floor ( n / 2 ) ; i ++ ) { let j = reverseNum ( i ) ; if ( i + j == n ) { document . write ( i + " " + j + " " ) ; return true ; } } document . write ( " " ) ; return false ; } let n = 121 ; isMysteryNumber ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function ReplaceElements ( arr , n ) { let prod = 1 ; for ( let i = 0 ; i < n ; ++ i ) { prod *= arr [ i ] ; } for ( let i = 0 ; i < n ; ++ i ) { arr [ i ] = parseInt ( prod / arr [ i ] , 10 ) ; } } let arr = [ 2 , 3 , 3 , 5 , 7 ] ; let n = arr . length ; ReplaceElements ( arr , n ) ; for ( let i = 0 ; i < n ; ++ i ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: prod
Iterator variables: i
Javascript program:
function Check_is_possible ( l , r , k ) { var count = 0 ; for ( i = l ; i <= r ; i ++ ) { if ( i % k == 0 ) { count ++ ; } } return ( count > 1 ) ; } var l = 4 , r = 12 ; var k = 5 ; if ( Check_is_possible ( l , r , k ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isValid ( N , K ) { let m1 = new Set ( ) ; let m2 = new Set ( ) ; while ( N > 0 ) { m1 . add ( N % 10 ) ; N = Math . floor ( N / 10 ) ; } while ( K > 0 ) { m2 . add ( K % 10 ) ; K = Math . floor ( K / 10 ) ; } let s = new Set ( [ ... m1 , ... m2 ] ) return s . size == m1 . size && s . size == m2 . size } function anyPermutation ( N , K ) { let powK = new Array ( 100 + 1 ) , Limit = ( Math . pow ( 10 , 18 ) ) ; for ( let i = 0 ; i < 101 ; i ++ ) powK [ i ] = 0 ; powK [ 0 ] = K ; let i = 1 ; while ( powK [ i - 1 ] * K < Limit ) { powK [ i ] = powK [ i - 1 ] * K ; i ++ ; } for ( let j = 0 ; j < i ; j ++ ) { if ( isValid ( N , powK [ j ] ) ) { return " " ; } } return " " ; } let N = 96889010407 , K = 7 ; document . write ( anyPermutation ( N , K ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function sumNth ( A , B , m , n ) { var res = 0 ; if ( n == 1 ) { for ( let i = 0 ; i < m ; i ++ ) res = res + A [ i ] ; } else if ( n == 2 ) { for ( let i = 0 ; i < m ; i ++ ) res = res + B [ i ] * m ; } else { var f = Array ( n ) . fill ( 0 ) ; f [ 0 ] = 0 ; f [ 1 ] = 1 ; for ( let i = 2 ; i < n ; i ++ ) f [ i ] = f [ i - 1 ] + f [ i - 2 ] ; for ( i = 0 ; i < m ; i ++ ) { res = res + ( m * ( B [ i ] * f [ n - 1 ] ) ) + ( m * ( A [ i ] * f [ n - 2 ] ) ) ; } } return res ; } var A = [ 1 , 2 , 3 ] ; var B = [ 4 , 5 , 6 ] ; var n = 3 ; var m = A . length ; document . write ( sumNth ( A , B , m , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } function isCousinPrime ( n1 , n2 ) { if ( Math . abs ( n1 - n2 ) != 4 ) return false ; else return ( isPrime ( n1 ) && isPrime ( n2 ) ) ; } var n1 = 7 , n2 = 11 ; if ( isCousinPrime ( n1 , n2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Iterator variables: i
Javascript program:
function isSemiprime ( num ) { var cnt = 0 ; for ( var i = 2 ; cnt < 2 && i * i <= num ; ++ i ) while ( num % i == 0 ) num /= i ++ cnt ; if ( num > 1 ) ++ cnt ; return cnt == 2 ; } function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } function isChenPrime ( n ) { if ( isPrime ( n ) && ( isSemiprime ( n + 2 ) || isPrime ( n + 2 ) ) ) return true ; else return false ; } var n = 7 ; if ( isChenPrime ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i, num
Iterator variables: i
Javascript program:
let N = 1000 ; let dp = new Array ( N + 1 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = 0 ; } function sieve ( ) { let arr = new Array ( N + 1 ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = 0 ; } arr [ 0 ] = 1 ; arr [ 1 ] = 1 ; for ( let i = 2 ; i <= Math . ceil ( Math . sqrt ( N ) + 1 ) ; i ++ ) if ( arr [ i ] == 0 ) for ( let j = i * i ; j <= N ; j += i ) arr [ j ] = 1 ; let runningPrimeSum = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { if ( arr [ i ] == 0 ) runningPrimeSum += i ; dp [ i ] = runningPrimeSum ; } } let l = 4 , r = 13 ; sieve ( ) ; document . write ( dp [ r ] - dp [ l - 1 ] ) ;

Index/key variables: i, j, r
Accumulator variables: i, j, runningPrimeSum
Iterator variables: i, j
Javascript program:
function findMinEqualSums ( a , N ) { let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; } let sum1 = 0 , sum2 = 0 ; let min = Number . MAX_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { sum1 += a [ i ] ; sum2 = sum - sum1 ; if ( Math . abs ( sum1 - sum2 ) < min ) { min = Math . abs ( sum1 - sum2 ) ; } if ( min == 0 ) { break ; } } return min ; } let a = [ 3 , 2 , 1 , 5 , 7 , 8 ] ; let N = a . length ; document . write ( findMinEqualSums ( a , N ) ) ;

Index/key variables: i
Accumulator variables: i, sum, sum1
Iterator variables: i
Javascript program:
var MAX = 10000 ; var prime = Array . from ( { length : parseInt ( ( MAX + 1.0 ) ) } , ( _ , i ) => false ) ; function SieveOfEratosthenes ( ) { for ( i = 0 ; i <= MAX ; i ++ ) prime [ i ] = true ; prime [ 1 ] = false ; for ( p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } } function solve ( n ) { var count = 0 , num = 1 ; var sum = 0 ; while ( count < n ) { if ( prime [ num ] ) { sum += num ; count ++ ; } num ++ ; } return parseInt ( sum ) ; } SieveOfEratosthenes ( ) ; var n = 4 ; document . write ( " " + solve ( n ) ) ;

Index/key variables: i, num, p
Accumulator variables: count, i, num, p, sum
Iterator variables: i, p
Javascript program:
function CountDigits ( n ) { if ( n == 1 ) return 1 ; var sum = 0 ; for ( i = 2 ; i <= n ; ++ i ) { sum += ( Math . log ( i ) / Math . log ( 10 ) ) ; } sum *= n ; return Math . ceil ( sum ) ; } var N = 5 ; document . write ( CountDigits ( N ) ) ;

Accumulator variables: sum
Iterator variables: i
Javascript program:
let MAX = 200006 ; let CONS = 32766 ; function calc ( a , b , lr , q , n ) { let M , m , i , j , k , l , r , suma , sumb , cc ; cc = 0 ; for ( i = 0 ; i < n - 1 ; ++ i ) { a [ i + 1 ] += a [ i ] ; b [ i + 1 ] += b [ i ] ; } while ( q != 0 ) { l = lr [ cc ++ ] ; r = lr [ cc ++ ] ; l -= 2 ; r -= 1 ; suma = a [ r ] ; sumb = b [ r ] ; if ( l >= 0 ) { suma -= a [ l ] ; sumb -= b [ l ] ; } M = Math . max ( CONS * suma + CONS * sumb , - CONS * suma - CONS * sumb ) ; M = Math . max ( M , Math . max ( CONS * suma - CONS * sumb , - CONS * suma + CONS * sumb ) ) ; m = Math . min ( CONS * suma + CONS * sumb , - CONS * suma - CONS * sumb ) ; m = Math . min ( m , Math . min ( CONS * suma - CONS * sumb , - CONS * suma + CONS * sumb ) ) ; document . write ( ( M - m ) + " " ) ; q -- ; } } let n = 5 , q = 2 ; let a = [ 0 , 7 , 3 , 4 , 5 ] ; let b = [ 0 , 3 , 1 , 2 , 3 ] ; let lr = new Array ( q * 2 ) ; lr [ 0 ] = 1 ; lr [ 1 ] = 1 ; lr [ 2 ] = 1 ; lr [ 3 ] = 3 ; calc ( a , b , lr , q , n ) ;

Index/key variables: i, l, r
Accumulator variables: cc, l, q, r, suma, sumb
Iterator variables: i
Javascript program:
power = Array ( 31 ) . fill ( 0 ) ; pre = Array ( 31 ) . fill ( 0 ) ; function PowerOfTwo ( ) { var x = 1 ; for ( i = 0 ; i < 31 ; i ++ ) { power [ i ] = x ; x *= 2 ; } pre [ 0 ] = 1 ; for ( i = 1 ; i < 31 ; i ++ ) pre [ i ] = pre [ i - 1 ] + power [ i ] ; } function Sum ( n ) { var ans = n * ( n + 1 ) / 2 ; for ( i = 0 ; i < 31 ; i ++ ) { if ( power [ i ] > n ) { ans -= 2 * pre [ i - 1 ] ; break ; } } return ans ; } PowerOfTwo ( ) ; var n = 4 ; document . write ( Sum ( n ) ) ;

Index/key variables: i
Accumulator variables: ans, i, x
Iterator variables: i
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } var n = 17 ; if ( isPrime ( n ) && ( n % 16 == 1 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Iterator variables: i
Javascript program:
function findNumber ( n ) { for ( i = n - 1 ; i >= 0 ; i -- ) { var count = Array . from ( { length : 10 } , ( _ , i ) => 0 ) ; var x = i ; var count1 = 0 , count2 = 0 ; while ( x > 0 ) { count [ x % 10 ] ++ ; x = parseInt ( x / 10 ) ; count1 ++ ; } for ( j = 0 ; j < 10 ; j ++ ) { if ( count [ j ] == 1 ) count2 ++ ; } if ( count1 == count2 ) return i ; } return - 1 ; } var n = 8490 ; document . write ( findNumber ( n ) ) ;

Index/key variables: j
Accumulator variables: count1, count2, i, j
Iterator variables: i, j
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function isPermutation ( first , second ) { var sum1 = 0 , sum2 = 0 , mul1 = 1 , mul2 = 1 ; var temp1 = first ; while ( temp1 != null ) { sum1 += temp1 . data ; mul1 *= temp1 . data ; temp1 = temp1 . next ; } var temp2 = second ; while ( temp2 != null ) { sum2 += temp2 . data ; mul2 *= temp2 . data ; temp2 = temp2 . next ; } return sum1 == sum2 && mul1 == mul2 ; } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } var first = null ; first = push ( first , 1 ) ; first = push ( first , 34 ) ; first = push ( first , 10 ) ; first = push ( first , 1 ) ; first = push ( first , 35 ) ; first = push ( first , 12 ) ; var second = null ; second = push ( second , 35 ) ; second = push ( second , 1 ) ; second = push ( second , 12 ) ; second = push ( second , 1 ) ; second = push ( second , 10 ) ; second = push ( second , 34 ) ; if ( isPermutation ( first , second ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: mul1, mul2, sum1, sum2
Class/struct names: Node
Javascript program:
function countDivisors ( n , k ) { var count = 0 , i ; for ( i = 1 ; i <= n ; i ++ ) { if ( n % i == 0 && i % k == 0 ) { count ++ ; } } return count ; } var n = 12 , k = 3 ; document . write ( countDivisors ( n , k ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
var MOD = 100000007 ; function power ( x , y , p ) { var res = 1 ; x = x % p ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function sumProd ( n , t ) { var dino = power ( t + 1 , MOD - 2 , MOD ) ; var ans = 1 ; for ( var i = n + t + 1 ; i > n ; -- i ) ans = ( ans % MOD * i % MOD ) % MOD ; var tfact = 1 ; for ( var i = 1 ; i <= t ; ++ i ) tfact = ( tfact * i ) % MOD ; ans = ans * dino - tfact + MOD ; return ans % MOD ; } var n = 3 , t = 2 ; document . write ( sumProd ( n , t ) ) ;

Iterator variables: i
Javascript program:
var mod = 107 ; function power ( a , b ) { var res = 1 ; while ( b != 0 ) { if ( ( b & 1 ) != 0 ) { res *= a ; res = res % mod ; } b = parseInt ( b / 2 ) ; a *= a ; a %= mod ; } return res ; } function minPlayer ( n , k ) { var num = ( ( power ( k , n ) - 1 ) + mod ) % mod ; var den = ( power ( k - 1 , mod - 2 ) + mod ) % mod ; var ans = ( ( ( num * den ) % mod ) * k ) % mod ; return ans ; } var n = 3 , k = 3 ; document . write ( minPlayer ( n , k ) ) ;

Accumulator variables: a, res
Javascript program:
function sieveOfEratosthenes ( N , s ) { let prime = new Array ( N + 1 ) ; for ( let i = 0 ; i < N + 1 ; i ++ ) prime [ i ] = false ; for ( let i = 2 ; i <= N ; i += 2 ) s [ i ] = 2 ; for ( let i = 3 ; i <= N ; i += 2 ) { if ( prime [ i ] == false ) { s [ i ] = i ; for ( let j = i ; j * i <= N ; j += 2 ) { if ( prime [ i * j ] == false ) { prime [ i * j ] = true ; s [ i * j ] = i ; } } } } } function findSum ( N ) { let s = new Array ( N + 1 ) ; let ans = 1 ; sieveOfEratosthenes ( N , s ) ; let currFactor = s [ N ] ; let power = 1 ; while ( N > 1 ) { N = Math . floor ( N / s [ N ] ) ; if ( currFactor == s [ N ] ) { power ++ ; continue ; } let sum = 0 ; for ( let i = 0 ; i <= power ; i ++ ) sum += Math . pow ( currFactor , i ) ; ans *= sum ; currFactor = s [ N ] ; power = 1 ; } return ans ; } let n = 12 ; document . write ( " " ) ; document . write ( findSum ( n ) ) ;

Index/key variables: N, i
Accumulator variables: ans, i, j, power, sum
Iterator variables: i, j
Javascript program:
function count_setbits ( N ) { var cnt = 0 ; while ( N > 0 ) { cnt += ( N & 1 ) ; N = N >> 1 ; } return cnt ; } function countMultiples ( n ) { var multiple = [ 2 , 3 , 5 ] ; var count = 0 , mask = parseInt ( Math . pow ( 2 , 3 ) ) ; for ( i = 1 ; i < mask ; i ++ ) { var prod = 1 ; for ( j = 0 ; j < 3 ; j ++ ) { if ( ( i & 1 << j ) > 0 ) prod = prod * multiple [ j ] ; } if ( count_setbits ( i ) % 2 == 1 ) count = count + parseInt ( n / prod ) ; else count = count - parseInt ( n / prod ) ; } return count ; } var n = 10 ; document . write ( countMultiples ( n ) ) ;

Index/key variables: j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function Circular ( n ) { var Result = 1 ; while ( n > 0 ) { Result = Result * n ; n -- ; } return Result ; } var n = 4 ; document . write ( Circular ( n - 1 ) ) ;

Accumulator variables: n
Javascript program:
function calTime ( arr , n ) { var work = 0 ; for ( i = 0 ; i < n ; i ++ ) work += 1 / arr [ i ] ; return 1 / work ; } var arr = [ 6.0 , 3.0 , 4.0 ] ; var n = arr . length ; document . write ( calTime ( arr , n ) . toFixed ( 5 ) + " " ) ;

Index/key variables: i
Accumulator variables: i, work
Iterator variables: i
Javascript program:
function printTwins ( low , high ) { let prime = new Array ( high + 1 ) ; let twin = false ; for ( let i = 0 ; i < high + 1 ; i ++ ) prime [ i ] = true ; prime [ 0 ] = prime [ 1 ] = false ; for ( let p = 2 ; p <= Math . floor ( Math . sqrt ( high ) ) + 1 ; p ++ ) { if ( prime [ p ] ) { for ( let i = p * 2 ; i <= high ; i += p ) prime [ i ] = false ; } } for ( let i = high ; i >= low ; i -- ) { if ( prime [ i ] && ( i - 2 >= low && prime [ i - 2 ] == true ) ) { document . write ( " " + ( i - 2 ) + " " + ( i ) + " " + " " ) ; twin = true ; break ; } } if ( twin == false ) document . write ( " " ) ; } printTwins ( 10 , 100 ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Boolean variables: twin
Javascript program:
function prevComplement ( n , b ) { var maxDigit , maxNum = 0 , digits = 0 , num = n ; while ( n != 0 ) { digits ++ ; n = parseInt ( n / 10 ) ; } maxDigit = b - 1 ; while ( ( digits -- ) > 0 ) { maxNum = maxNum * 10 + maxDigit ; } return maxNum - num ; } function complement ( n , b ) { return prevComplement ( n , b ) + 1 ; } document . write ( prevComplement ( 25 , 7 ) + " " ) ; document . write ( complement ( 25 , 7 ) ) ;

Accumulator variables: digits
Javascript program:
function MaximumDivisors ( X , Y ) { let arr = new Array ( Y - X + 1 ) ; for ( let i = 0 ; i < arr . length ; i ++ ) arr [ i ] = 0 ; let mx = 0 ; let cnt = 0 ; for ( let i = 1 ; i * i <= Y ; i ++ ) { let sq = i * i ; let first_divisible ; if ( Math . floor ( X / i ) * i >= X ) first_divisible = Math . floor ( X / i ) * i ; else first_divisible = ( Math . floor ( X / i ) + 1 ) * i ; for ( let j = first_divisible ; j <= Y ; j += i ) { if ( j < sq ) continue ; else if ( j == sq ) arr [ j - X ] ++ ; else arr [ j - X ] += 2 ; } } for ( let i = X ; i <= Y ; i ++ ) { if ( arr [ i - X ] > mx ) { cnt = 1 ; mx = arr [ i - X ] ; } else if ( arr [ i - X ] == mx ) cnt ++ ; } return cnt ; } let X = 1 , Y = 10 ; document . write ( MaximumDivisors ( X , Y ) ) ;

Index/key variables: i
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function print_C ( p0 ) { let p1 = 0 ; let i = 0 ; let x ; let flag ; let k ; while ( 1 ) { flag = 1 ; x = Math . pow ( 2 , i ) ; p1 = x * p0 + ( x - 1 ) ; for ( let k = 2 ; k < p1 ; k ++ ) { if ( p1 % k == 0 ) { flag = 0 ; break ; } } if ( flag == 0 ) break ; document . write ( p1 + " " ) ; i ++ ; } } let p0 = 2 ; print_C ( p0 ) ;

Accumulator variables: i, k
Iterator variables: k
Javascript program:
function findOddPair ( A , N ) { var i , j ; var oddPair = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { if ( ( A [ i ] & A [ j ] ) % 2 != 0 ) oddPair ++ ; } } return oddPair ; } var a = [ 5 , 1 , 3 , 2 ] ; var n = a . length ; document . write ( findOddPair ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, oddPair
Iterator variables: i, j
Javascript program:
function summ ( n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } function printDigitalRoot ( n ) { var maxi = 1 ; var dig = 1 ; for ( i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { var d1 = summ ( n / i ) ; var d2 = summ ( i ) ; if ( d1 > maxi ) { dig = n / i ; maxi = d1 ; } if ( d2 > maxi ) { dig = i ; maxi = d2 ; } if ( d1 == maxi ) { if ( dig < ( n / i ) ) { dig = n / i ; maxi = d1 ; } } if ( d2 == maxi ) { if ( dig < i ) { dig = i ; maxi = d2 ; } } } } document . write ( dig + " " + maxi ) ; } var n = 10 ; printDigitalRoot ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function calculateFraction ( num , den ) { if ( num == 0 ) return " " ; var sign = ( num < 0 ) ^ ( den < 0 ) ? - 1 : 1 ; num = Math . abs ( num ) ; den = Math . abs ( den ) ; var initial = parseInt ( num / den ) ; var res = [ ] ; if ( sign == - 1 ) res . push ( " " ) ; res . push ( initial . toString ( ) ) ; if ( num % den == 0 ) return res ; res . push ( " " ) ; var rem = num % den ; var mp = new Map ( ) ; var index ; var repeating = false ; while ( rem > 0 && ! repeating ) { if ( mp . has ( rem ) ) { index = mp . get ( rem ) ; repeating = true ; break ; } else mp . set ( rem , res . length ) ; rem = rem * 10 ; var temp = parseInt ( rem / den ) ; res . push ( temp . toString ( ) ) ; rem = rem % den ; } if ( repeating ) { res . push ( " " ) ; res . splice ( index , 0 , " " ) ; } return res . join ( ' ' ) ; } var num = 50 , den = 22 ; document . write ( calculateFraction ( num , den ) + " " ) ; num = - 1 , den = 2 ; document . write ( calculateFraction ( num , den ) ) ;

Boolean variables: repeating
Javascript program:
function checkEqual ( S ) { for ( var i = 0 ; i < S . length ; i ++ ) { if ( S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' ) { return " " ; } } var start = 0 , end = S . length - 1 ; while ( start < end ) { if ( S [ start ] != S [ end ] ) { return " " ; } start ++ ; end -- ; } return " " ; } var S = " " ; document . write ( checkEqual ( S ) ) ;

Index/key variables: end, i, start
Accumulator variables: end, i, start
Iterator variables: i