dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function binToDecimal3 ( n ) { var a = Array ( 64 ) . fill ( 0 ) ; var x = 0 , i ; for ( i = 0 ; n > 0 ; i ++ ) { a [ i ] = n % 2 ; n = parseInt ( n / 2 ) ; } x = ( i < 3 ) ? 3 : i ; var d = 0 , p = 0 ; for ( var i = x - 3 ; i < x ; i ++ ) d += a [ i ] * parseInt ( Math . pow ( 2 , p ++ ) ) ; document . write ( d + " " ) ; d = 0 ; p = 0 ; for ( var i = 0 ; i < 3 ; i ++ ) d += a [ i ] * parseInt ( Math . pow ( 2 , p ++ ) ) ; document . write ( d ) ; } var n = 86 ; binToDecimal3 ( n ) ;

Index/key variables: i
Accumulator variables: d, i, p
Iterator variables: i
Javascript program:
function isPowerOfTwo ( x ) { if ( x == 0 ) return false ; if ( ( x & ( x - 1 ) ) == 0 ) return true ; else return false ; } function countNum ( a , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPowerOfTwo ( a [ i ] ) || isPowerOfTwo ( a [ i ] + 1 ) ) count ++ ; } return count ; } let arr = [ 5 , 6 , 9 , 3 , 1 ] ; let n = arr . length ; document . write ( countNum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function checkEvenParity ( x ) { let parity = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; parity ++ ; } if ( parity % 2 == 0 ) return true ; else return false ; } function sumlist ( a , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( checkEvenParity ( a [ i ] ) ) sum += a [ i ] ; } return sum ; } let arr = [ 2 , 4 , 3 , 5 , 9 ] ; let n = arr . length ; document . write ( sumlist ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, parity, sum
Iterator variables: i
Javascript program:
function findOddPair ( A , N ) { let oddPair = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( ( A [ i ] A [ j ] ) % 2 != 0 ) oddPair ++ ; } } return oddPair ; } let A = [ 5 , 6 , 2 , 8 ] ; let 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 findevenPair ( A , N ) { let i , j ; let evenPair = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { if ( ( A [ i ] ^ A [ j ] ) % 2 == 0 ) evenPair ++ ; } } return evenPair ; } let A = [ 5 , 4 , 7 , 2 , 1 ] ; let N = A . length ; document . write ( findevenPair ( A , N ) ) ;

Index/key variables: i, j
Accumulator variables: evenPair, i, j
Iterator variables: i, j
Javascript program:
function findEvenPair ( A , N ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( A [ i ] % 2 != 0 ) count ++ ; } let totalPairs = parseInt ( N * ( N - 1 ) / 2 ) ; let oddEvenPairs = count * ( N - count ) ; return totalPairs - oddEvenPairs ; } let a = [ 5 , 4 , 7 , 2 , 1 ] ; let n = a . length ; document . write ( findEvenPair ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findevenPair ( A , N ) { let i , j ; let evenPair = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { if ( ( A [ i ] & A [ j ] ) % 2 == 0 ) evenPair ++ ; } } return evenPair ; } let a = [ 5 , 1 , 3 , 2 ] ; let n = a . length ; document . write ( findevenPair ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: evenPair, i, j
Iterator variables: i, j
Javascript program:
function findevenPair ( A , N ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) if ( A [ i ] % 2 != 0 ) count ++ ; let oddCount = parseInt ( ( count * ( count - 1 ) ) / 2 ) ; return parseInt ( ( N * ( N - 1 ) ) / 2 ) - oddCount ; } let a = [ 5 , 1 , 3 , 2 ] ; let n = a . length ; document . write ( findevenPair ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function xorGivenSetBits ( arr , n , k ) { let v = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( bitcount ( arr [ i ] ) == k ) { v . push ( arr [ i ] ) ; } } let result = v [ 0 ] ; for ( let i = 1 ; i < v . length ; i ++ ) result = result ^ v [ i ] ; return result ; } function bitcount ( n ) { var count = 0 ; while ( n ) { count += n & 1 ; n >>= 1 ; } return count ; } let arr = [ 2 , 13 , 1 , 19 , 7 ] ; let n = arr . length ; let k = 3 ; document . write ( xorGivenSetBits ( arr , n , k ) ) ;

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

Index/key variables: i
Accumulator variables: X
Iterator variables: i
Javascript program:
let sizeofInt = 8 ; function countZeros ( x ) { let total_bits = sizeofInt * 8 ; let res = 0 ; while ( ( x & ( 1 << ( total_bits - 1 ) ) ) == 0 ) { x = ( x << 1 ) ; res ++ ; } return res ; } let x = 101 ; document . write ( countZeros ( x ) ) ;

Accumulator variables: res
Javascript program:
function solve ( A , B ) { var count = 0 ; for ( i = 0 ; i < 32 ; i ++ ) { if ( ( ( A >> i ) & 1 ) != ( ( B >> i ) & 1 ) ) { count ++ ; } } document . write ( " " + count ) ; } var A = 12 , B = 15 ; solve ( A , B ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . left = null ; this . right = null ; this . data = data ; } } function newNode ( data ) { let node = new Node ( data ) ; return ( node ) ; } function bitCount ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } function printSetBit ( root ) { if ( root == null ) return ; document . write ( " " + root . data + " " + bitCount ( root . data ) + " " ) ; printSetBit ( root . left ) ; printSetBit ( root . right ) ; } let root = newNode ( 16 ) ; root . left = newNode ( 13 ) ; root . left . left = newNode ( 14 ) ; root . left . right = newNode ( 12 ) ; root . right = newNode ( 11 ) ; root . right . left = newNode ( 10 ) ; root . right . right = newNode ( 16 ) ; printSetBit ( root ) ;

Accumulator variables: setBits
Class/struct names: Node
Javascript program:
function AND ( a , n ) { let ans = a [ 0 ] ; for ( let i = 0 ; i < n ; ++ i ) ans &= a [ i ] ; return ans ; } let a = [ 1 , 2 , 3 ] ; let n = a . length ; document . write ( AND ( a , n ) ) ;

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Javascript program:
function TwoscomplementbyXOR ( str ) { let n = str . length ; let check_bit = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == ' ' && check_bit == 0 ) { continue ; } else { if ( check_bit == 1 ) { if ( str . charAt ( i ) == ' ' ) str = str . substr ( 0 , i ) + ' ' + str . substr ( i + 1 ) ; else str = str . substr ( 0 , i ) + ' ' + str . substr ( i + 1 ) ; } check_bit = 1 ; } } if ( check_bit == 0 ) return " " + str ; else return str ; } let str = " " ; document . write ( TwoscomplementbyXOR ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function bitsAreInAltPatrnInGivenTRange ( n , l , r ) { var num , prev , curr ; num = n >> ( l - 1 ) ; prev = num & 1 ; num = num >> 1 ; for ( var i = 1 ; i <= ( r - l ) ; i ++ ) { curr = num & 1 ; if ( curr == prev ) return false ; prev = curr ; num = num >> 1 ; } return true ; } var n = 18 ; var l = 1 , r = 3 ; if ( bitsAreInAltPatrnInGivenTRange ( n , l , r ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function MakePreSum ( arr , presum , n ) { presum [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) presum [ i ] = presum [ i - 1 ] + arr [ i ] ; } function BinaryLifting ( presum , n , k ) { let pos = 0 ; let LOGN = Math . log ( n ) ; if ( x <= presum [ 0 ] ) return 0 ; for ( let i = LOGN ; i >= 0 ; i -- ) { if ( pos + ( 1 << i ) < n && presum [ pos + ( 1 << i ) ] < x ) { pos += ( 1 << i ) ; } } return pos + 1 ; } let arr = [ 2 , 5 , 7 , 1 , 6 , 9 , 12 , 4 , 6 ] ; let x = 8 ; let n = arr . length ; let presum = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { presum [ i ] = 0 ; } MakePreSum ( arr , presum , n ) ; document . write ( BinaryLifting ( presum , n , x ) ) ;

Index/key variables: i
Accumulator variables: i, pos
Iterator variables: i
Javascript program:
function bit_count ( n ) { var count = 0 ; while ( n ) { count ++ ; n = n & ( n - 1 ) ; } return count ; } function maxsum ( arr , n ) { var bits = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { bits [ i ] = bit_count ( arr [ i ] ) ; } var sum = Array ( 32 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { sum [ bits [ i ] ] += arr [ i ] ; } var maximum = 0 ; for ( var i = 0 ; i < 32 ; i ++ ) { maximum = Math . max ( sum [ i ] , maximum ) ; } return maximum ; } var arr = [ 2 , 3 , 8 , 5 , 6 , 7 ] ; var n = arr . length ; document . write ( maxsum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function xorPairSum ( ar , n ) { var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum = sum ^ ar [ i ] ; return 2 * sum ; } var arr = [ 1 , 2 , 3 ] ; var n = arr . length ; document . write ( xorPairSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findEvenPair ( A , N ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) if ( ( ! ( ( A [ i ] & 1 ) > 0 ) ) ) count ++ ; return count * ( count - 1 ) / 2 ; } let A = [ 5 , 6 , 2 , 8 ] ; let N = A . length ; document . write ( findEvenPair ( A , N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function checkSame ( n ) { let set = 0 , unset = 0 ; while ( n ) { if ( n & 1 ) set ++ ; else unset ++ ; n = n >> 1 ; } if ( set == unset ) return true ; else return false ; } let n = 12 ; if ( checkSame ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: set, unset
Javascript program:
function isBalanced ( s ) { let st = [ ] ; let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) { st . push ( s [ i ] ) ; } else if ( st . length == 0 ) { return false ; } else { st . pop ( ) ; } } if ( st . length != 0 ) { return false ; } return true ; } function isBalancedSeq ( s1 , s2 ) { if ( isBalanced ( s1 + s2 ) ) { return true ; } return isBalanced ( s2 + s1 ) ; } let s1 = " " ; let s2 = " " ; if ( isBalancedSeq ( s1 , s2 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function KthCharacter ( m , n , k ) { let distance = Math . pow ( 2 , n ) ; let Block_number = Math . floor ( k / distance ) ; let remaining = k % distance ; let s = new Array ( 32 ) . fill ( 0 ) ; let x = 0 ; for ( ; m > 0 ; x ++ ) { s [ x ] = m % 2 ; m = Math . floor ( m / 2 ) ; } let root = s [ x - 1 - Block_number ] ; if ( remaining == 0 ) { document . write ( root ) ; return ; } let flip = true ; while ( remaining > 1 ) { if ( ( remaining & 1 ) > 0 ) { flip = ! flip ; } remaining = remaining >> 1 ; } if ( flip ) { document . write ( ( root > 0 ) ? 0 : 1 ) ; } else { document . write ( root ) ; } } let m = 5 , k = 5 , n = 3 ; KthCharacter ( m , n , k ) ;

Index/key variables: x
Accumulator variables: x
Boolean variables: flip
Javascript program:
function getInteger ( L , R ) { var number = 0 ; for ( var i = L ; i <= R ; i ++ ) number += Math . pow ( 2 , i ) ; return number ; } var L = 2 , R = 5 ; document . write ( getInteger ( L , R ) ) ;

Accumulator variables: i, number
Iterator variables: i
Javascript program:
function findXor ( arr , n ) { let xoR = 0 ; for ( let i = 0 ; i < n ; i ++ ) { xoR = xoR ^ arr [ i ] ; } return xoR * 2 ; } let arr = [ 1 , 5 , 6 ] ; let n = arr . length ; document . write ( findXor ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function setBitwiseORk ( n ) { var v = [ ] ; for ( var i = 0 ; i <= n ; i ++ ) { if ( ( i n ) == n ) v . push ( i ) ; } for ( var i = 0 ; i < v . length ; i ++ ) document . write ( v [ i ] + ' ' ) ; } var n = 5 ; setBitwiseORk ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printOdds ( arr , n ) { let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) res = res ^ arr [ i ] ; let set_bit = res & ( ~ ( res - 1 ) ) ; let x = 0 , y = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] & set_bit ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } document . write ( x + " " + y ) ; } let arr = [ 2 , 3 , 3 , 4 , 4 , 5 ] ; let n = arr . length ; printOdds ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function subsetBitwiseORk ( arr , n , k ) { var v = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] k ) == k ) v . push ( arr [ i ] ) ; } var ans = 0 ; for ( var i = 0 ; i < v . length ; i ++ ) ans |= v [ i ] ; if ( ans != k ) { document . write ( " " ) ; return ; } for ( var i = 0 ; i < v . length ; i ++ ) document . write ( v [ i ] + ' ' ) ; } var k = 3 ; var arr = [ 1 , 4 , 2 ] ; var n = arr . length ; subsetBitwiseORk ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findEletobeInserted ( A , n , k ) { var ans = k ; for ( var i = 0 ; i < n ; i ++ ) ans ^= A [ i ] ; return ans ; } var A = [ 1 , 2 , 3 , 4 , 5 ] ; var n = A . length ; var k = 10 ; document . write ( findEletobeInserted ( A , n , k ) + " " + " " + " " + k ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
var BitCount = Array . from ( { length : 10000 } , ( _ , i ) => 0 ) ; function fillSetBitsMatrix ( arr , n ) { for ( i = 0 ; i < 32 ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { var temp = arr [ j ] >> i ; if ( temp % 2 != 0 ) BitCount [ j ] += 1 ; } } for ( i = 1 ; i < n ; i ++ ) BitCount [ i ] += BitCount [ i - 1 ] ; } function Query ( Q , q ) { for ( i = 0 ; i < q ; i ++ ) document . write ( ( BitCount [ Q [ i ] [ 1 ] ] - BitCount [ Q [ i ] [ 0 ] - 1 ] ) + " " ) ; } var Arr = [ 1 , 5 , 6 , 10 , 9 , 4 , 67 ] ; var n = Arr . length ; fillSetBitsMatrix ( Arr , n ) ; var q = 2 ; var Q = [ [ 1 , 5 ] , [ 2 , 6 ] ] ; Query ( Q , q ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function decimalToBinaryNumber ( x , n ) { var binaryNumber = Array ( x ) ; var i = 0 ; while ( x > 0 ) { binaryNumber [ i ] = x % 2 ; x = parseInt ( x / 2 ) ; i ++ ; } for ( var j = 0 ; j < n - i ; j ++ ) document . write ( ' ' ) ; for ( var j = i - 1 ; j >= 0 ; j -- ) document . write ( binaryNumber [ j ] ) ; } function generateGrayarr ( n ) { var N = 1 << n ; for ( var i = 0 ; i < N ; i ++ ) { var x = i ^ ( i >> 1 ) ; decimalToBinaryNumber ( x , n ) ; document . write ( " " ) ; } } var n = 3 ; generateGrayarr ( n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var BITS = 32 ; function andSum ( arr , n ) { var ans = 0 ; for ( i = 0 ; i < BITS ; i ++ ) { var countSetBits = 0 ; for ( j = 0 ; j < n ; j ++ ) { if ( ( arr [ j ] & ( 1 << i ) ) != 0 ) countSetBits ++ ; } var subset = ( 1 << countSetBits ) - 1 ; subset = ( subset * ( 1 << i ) ) ; ans += subset ; } return ans ; } var arr = [ 1 , 2 , 3 ] ; var size = 3 ; document . write ( andSum ( arr , size ) ) ;

Index/key variables: j
Accumulator variables: ans, countSetBits, i, j
Iterator variables: i, j
Javascript program:
function _popcnt32 ( number ) { let count = 0 ; while ( number > 0 ) { count += number & 1 ; number >>= 1 ; } return count ; } function minimize ( a ) { let n = _popcnt32 ( a ) ; return ( Math . pow ( 2 , n ) - 1 ) ; } let a = 11 ; document . write ( minimize ( a ) ) ;

Accumulator variables: count
Javascript program:
function countSetBits ( n ) { var count = 0 ; while ( n ) { count += n & 1 ; n >>= 1 ; } return count ; } var i = 3 ; document . write ( countSetBits ( i ) ) ;

Accumulator variables: count
Javascript program:
function isEven ( n ) { let isEven = true ; for ( let i = 1 ; i <= n ; i ++ ) isEven = ! isEven ; return isEven ; } let n = 101 ; if ( isEven ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Boolean variables: isEven
Javascript program:
function checkValidPair ( num1 , num2 ) { var s1 = num1 . toString ( ) ; var s2 = num2 . toString ( ) ; var i , j ; for ( i = 0 ; i < s1 . length ; i ++ ) for ( j = 0 ; j < s2 . length ; j ++ ) if ( s1 [ i ] == s2 [ j ] ) return true ; return false ; } function countPairs ( arr , n ) { var numberOfPairs = 0 ; for ( i = 0 ; i < n ; i ++ ) for ( j = i + 1 ; j < n ; j ++ ) if ( checkValidPair ( arr [ i ] , arr [ j ] ) ) numberOfPairs ++ ; return numberOfPairs ; } var arr = [ 10 , 12 , 24 ] ; var n = arr . length ; ; document . write ( countPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, numberOfPairs
Iterator variables: i, j
Javascript program:
var NUM_BITS = 32 ; function isPowerOf2 ( num ) { return ( num && ! ( num & ( num - 1 ) ) ) ; } function checkSubsequence ( arr , n ) { if ( n == 1 ) return isPowerOf2 ( arr [ 0 ] ) ; var total = 0 ; for ( var i = 0 ; i < NUM_BITS ; i ++ ) total = total | ( 1 << i ) ; for ( var i = 0 ; i < NUM_BITS ; i ++ ) { var ans = total ; for ( var j = 0 ; j < n ; j ++ ) { if ( arr [ j ] & ( 1 << i ) ) ans = ans & arr [ j ] ; } if ( isPowerOf2 ( ans ) ) return true ; } return false ; } var arr = [ 12 , 13 , 7 ] ; var n = arr . length ; if ( checkSubsequence ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function getMid ( s , e ) { return s + Math . floor ( ( e - s ) / 2 ) ; } function constructSTUtil ( arr , ss , se , st , si , operation ) { if ( ss == se ) { st [ si ] = arr [ ss ] ; return ; } let mid = getMid ( ss , se ) ; constructSTUtil ( arr , ss , mid , st , si * 2 + 1 , ! operation ) ; constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 , ! operation ) ; if ( operation ) { st [ si ] = ( st [ 2 * si + 1 ] st [ 2 * si + 2 ] ) ; } else { st [ si ] = ( st [ 2 * si + 1 ] ^ st [ 2 * si + 2 ] ) ; } } function constructST ( arr , n ) { let x = Math . ceil ( Math . log ( n ) / Math . log ( 2 ) ) ; let max_size = 2 * Math . pow ( 2 , x ) - 1 ; let st = new Array ( max_size ) ; let operationAtRoot = ! ( x % 2 == 0 ) ; constructSTUtil ( arr , 0 , n - 1 , st , 0 , operationAtRoot ) ; return st ; } let leaves = [ 1 , 6 , 3 , 7 , 5 , 9 , 10 , 4 ] ; let n = leaves . length ; let segmentTree = constructST ( leaves , n ) ; let rootIndex = 0 ; document . write ( " " + segmentTree [ rootIndex ] ) ;

Index/key variables: rootIndex, si, ss
Javascript program:
var N = 1000 function lastElement ( a , n ) { var steps = 1 ; var v = Array . from ( Array ( N ) , ( ) => Array ( 0 ) ) ; if ( n == 1 ) return a [ 0 ] ; for ( var i = 0 ; i < n ; i += 2 ) v [ steps ] . push ( a [ i ] a [ i + 1 ] ) ; while ( v [ steps ] . length > 1 ) { steps += 1 ; for ( var i = 0 ; i < v [ steps - 1 ] . length ; i += 2 ) { if ( steps & 1 ) v [ steps ] . push ( v [ steps - 1 ] [ i ] v [ steps - 1 ] [ i + 1 ] ) ; v [ steps ] . push ( v [ steps - 1 ] [ i ] ^ v [ steps - 1 ] [ i + 1 ] ) ; } } return v [ steps ] [ 0 ] ; } var a = [ 1 , 4 , 5 , 6 ] ; var n = a . length ; var index = 0 ; var value = 2 ; a [ 0 ] = 2 ; document . write ( lastElement ( a , n ) + " " ) ; index = 3 ; value = 5 ; a [ index ] = value ; document . write ( lastElement ( a , n ) ) ;

Index/key variables: i, index, steps
Accumulator variables: i, steps
Iterator variables: i
Javascript program:
function findWinner ( A , n ) { let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) res ^= A [ i ] ; if ( res == 0 n % 2 == 0 ) return " " ; else return " " ; } let A = [ 1 , 4 , 3 , 5 ] ; let n = A . length ; document . write ( " " + findWinner ( A , n ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function divide ( dividend , divisor ) { var sign = ( ( dividend < 0 ) ? 1 : 0 ^ ( divisor < 0 ) ? 1 : 0 ) ? - 1 : 1 ; dividend = Math . abs ( dividend ) ; divisor = Math . abs ( divisor ) ; var quotient = 0 , temp = 0 ; while ( dividend >= divisor ) { dividend -= divisor ; ++ quotient ; } if ( sign == - 1 ) quotient = - quotient ; return quotient ; } var a = 10 , b = 3 ; document . write ( divide ( a , b ) + " " ) ; var a1 = 43 , b1 = - 8 ; document . write ( divide ( a1 , b1 ) + " " ) ;

Accumulator variables: dividend
Javascript program:
function count ( n ) { let c = 0 ; while ( n != 0 ) { c ++ ; n = n >> 1 ; } return c ; } function XOR ( a , b ) { let c = Math . min ( a , b ) ; let d = Math . max ( a , b ) ; if ( count ( c ) < count ( d ) ) c = c << ( count ( d ) - count ( c ) ) ; return ( c ^ d ) ; } let a = 13 , b = 5 ; document . write ( XOR ( a , b ) ) ;

Accumulator variables: c
Javascript program:
function CheckDivisibilty ( A ) { var oddbits = 0 , evenbits = 0 ; for ( var counter = 0 ; counter < A . length ; counter ++ ) { if ( A [ counter ] == ' ' ) { if ( counter % 2 == 0 ) { evenbits ++ ; } else { oddbits ++ ; } } } if ( Math . abs ( oddbits - evenbits ) % 3 == 0 ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } var A = " " ; CheckDivisibilty ( A ) ;

Index/key variables: counter
Accumulator variables: counter, evenbits, oddbits
Iterator variables: counter
Javascript program:
function setevenbits ( n ) { var temp = n ; var count = 0 ; var res = 0 ; for ( temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 1 ) res |= ( 1 << count ) ; count ++ ; } return ( n & res ) ; } function setoddbits ( m ) { var count = 0 ; var res = 0 ; for ( temp = m ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 0 ) res |= ( 1 << count ) ; count ++ ; } return ( m & res ) ; } function getAlternateBits ( n , m ) { var tempn = setevenbits ( n ) ; var tempm = setoddbits ( m ) ; return ( tempn tempm ) ; } var n = 10 ; var m = 11 ; document . write ( getAlternateBits ( n , m ) ) ;

Accumulator variables: count, res
Iterator variables: temp
Javascript program:
function isDivisibleBy10 ( bin , n ) { if ( bin [ n - 1 ] == ' ' ) return false ; var sum = 0 ; for ( var i = n - 2 ; i >= 0 ; i -- ) { if ( bin [ i ] == ' ' ) { var posFromRight = n - i - 1 ; if ( posFromRight % 4 == 1 ) sum = sum + 2 ; else if ( posFromRight % 4 == 2 ) sum = sum + 4 ; else if ( posFromRight % 4 == 3 ) sum = sum + 8 ; else if ( posFromRight % 4 == 0 ) sum = sum + 6 ; } } if ( sum % 10 == 0 ) return true ; return false ; } function isDivisibleBy20 ( bin , n ) { if ( bin [ n - 1 ] == ' ' ) return false ; return isDivisibleBy10 ( bin , n - 1 ) ; } var bin = " " ; var n = bin . length ; if ( isDivisibleBy20 ( bin , n - 1 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function evenbittogglenumber ( n ) { let res = 0 , count = 0 ; for ( let temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 1 ) res |= ( 1 << count ) ; count ++ ; } return n ^ res ; } let n = 11 ; document . write ( evenbittogglenumber ( n ) ) ;

Accumulator variables: count, res
Iterator variables: temp
Javascript program:
function takeLandFsetbits ( n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return ( ( n + 1 ) >> 1 ) + 1 ; } function toggleFandLbits ( n ) { if ( n == 1 ) return 0 ; return n ^ takeLandFsetbits ( n ) ; } let n = 10 ; document . write ( toggleFandLbits ( n ) ) ;

Accumulator variables: n
Javascript program:
function countSetBits ( n ) { let count = 0 ; while ( n != 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } function checkOdious ( n ) { return ( countSetBits ( n ) % 2 == 1 ) ; } let num = 32 ; if ( checkOdious ( num ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: count, n
Javascript program:
function setleftmostunsetbit ( n ) { if ( ( n & ( n + 1 ) ) == 0 ) return n ; let pos = 0 ; for ( let temp = n , count = 0 ; temp > 0 ; temp >>= 1 , count ++ ) if ( ( temp & 1 ) == 0 ) pos = count ; return ( n | ( 1 << ( pos ) ) ) ; } let n = 10 ; document . write ( setleftmostunsetbit ( n ) ) ;

Accumulator variables: count
Iterator variables: temp