dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findNumbers ( n ) { var ans = " " ; for ( var i = 0 ; i < n - 1 ; i ++ ) ans += ' ' ; var even = ans + ' ' ; var odd = ans + ' ' ; document . write ( " " + even + " " ) ; document . write ( " " + odd + " " ) ; } var n = 4 ; findNumbers ( n ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findMissing ( arr , n , k , avg ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } var num = ( avg * ( n + k ) ) - sum ; var den = k ; if ( num % den != 0 ) return - 1 ; return ( Math . floor ( num / den ) ) ; } var k = 3 ; var avg = 4 ; var arr = [ 2 , 7 , 3 ] ; var n = arr . length ; document . write ( findMissing ( arr , n , k , avg ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function binomialCoeff ( n , k ) { if ( k == 0 k == n ) return 1 ; return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ; } function fact ( n ) { if ( n >= 1 ) return n * fact ( n - 1 ) ; else return 1 ; } function isVowel ( ch ) { if ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) { return true ; } return false ; } function countWords ( s , p , q ) { var countc = 0 , countv = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( isVowel ( s [ i ] ) ) countv ++ ; else countc ++ ; } var a = binomialCoeff ( countc , p ) ; var b = binomialCoeff ( countv , q ) ; var c = fact ( p + q ) ; var ans = ( a * b ) * c ; return ans ; } var s = " " ; var p = 4 , q = 3 ; document . write ( countWords ( s , p , q ) ) ;

Index/key variables: i
Accumulator variables: countc, countv, i
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function generateArr ( A , n ) { let B = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { let cnt = 0 ; for ( let j = 0 ; j < i ; j ++ ) { if ( A [ j ] % A [ i ] == 0 ) cnt ++ ; } B [ i ] = cnt ; } printArr ( B , n ) ; } let A = [ 3 , 5 , 1 ] ; let n = A . length ; generateArr ( A , n ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function product ( a , n ) { var ans = 1 ; var val = Math . pow ( 2 , n - 1 ) ; for ( var i = 0 ; i < n ; i ++ ) { ans *= Math . pow ( a [ i ] , val ) ; } return ans ; } var n = 2 ; a = [ 3 , 7 ] document . write ( product ( a , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findPair ( arr , n ) { if ( n < 2 ) { document . write ( " " ) ; return ; } let i , first , second ; first = second = - 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second ) { second = arr [ i ] ; } } document . write ( " " + first + " " + second ) ; } let arr = [ 0 , 2 , 3 , 4 , 1 , 6 , 8 , 9 ] ; let n = arr . length ; findPair ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sum ( arr , n ) { var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } sum = sum * parseInt ( Math . pow ( 2 , n - 1 ) ) ; return sum ; } var arr = [ 2 , 1 , 5 , 6 ] ; var n = arr . length ; document . write ( sum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function triangle ( n ) { var k = 2 * n - 2 ; var ch = 1 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < k ; j ++ ) document . write ( " " ) ; k = k - 1 ; for ( var j = 0 ; j <= i ; j ++ ) { document . write ( ch ++ + " " ) ; } document . write ( " " ) ; } } function maxHeight ( n ) { return parseInt ( ( ( parseInt ( Math . sqrt ( 1 + 8.0 * n ) ) ) - 1 ) / 2 ) ; } var N = 9 ; triangle ( maxHeight ( N ) ) ;

Accumulator variables: ch, i, j
Iterator variables: i, j
Javascript program:
function no_of_ways ( a , n ) { let count_0 = 0 , count_1 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) count_0 ++ ; else count_1 ++ ; } if ( count_1 % 2 == 0 ) return count_0 ; else return count_1 ; } let n = 4 ; let a1 = [ 1 , 1 , 0 , 0 ] ; document . write ( no_of_ways ( a1 , n ) + " " ) ; n = 5 ; let a2 = [ 1 , 1 , 1 , 0 , 0 ] ; document . write ( no_of_ways ( a2 , n ) + " " ) ; n = 5 ; let a3 = [ 1 , 1 , 0 , 0 , 0 ] ; document . write ( no_of_ways ( a3 , n ) + " " ) ; n = 6 ; let a4 = [ 1 , 1 , 1 , 0 , 0 , 0 ] ; document . write ( no_of_ways ( a4 , n ) + " " ) ;

Index/key variables: i
Accumulator variables: count_0, count_1, i
Iterator variables: i
Javascript program:
function maxInt ( str ) { var str2 = " " ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] < ' ' ) { var l = ( ' ' . charCodeAt ( 0 ) - str [ i ] . charCodeAt ( 0 ) ) + ' ' . charCodeAt ( 0 ) ; str2 = str2 . concat ( String . fromCharCode ( l ) ) ; } } if ( str2 [ 0 ] == ' ' ) str2 [ 0 ] = ' ' ; return str2 ; } var str = " " ; document . write ( maxInt ( str ) )

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function longest_gap ( N ) { let distance = 0 , count = 0 , first_1 = - 1 , last_1 = - 1 ; while ( N ) { count ++ ; let r = N & 1 ; if ( r == 1 ) { first_1 = first_1 == - 1 ? count : first_1 ; last_1 = count ; } N = parseInt ( N / 2 ) ; } if ( last_1 <= first_1 ) { return - 1 ; } else { distance = ( last_1 - first_1 - 1 ) ; return distance ; } } let N = 131 ; document . write ( longest_gap ( N ) + " " ) ; N = 8 ; document . write ( longest_gap ( N ) + " " ) ; N = 17 ; document . write ( longest_gap ( N ) + " " ) ; N = 33 ; document . write ( longest_gap ( N ) + " " ) ;

Accumulator variables: count
Javascript program:
const MAX = 10 ; function isFactorion ( n ) { let fact = new Array ( MAX ) ; fact [ 0 ] = 1 ; for ( let i = 1 ; i < MAX ; i ++ ) fact [ i ] = i * fact [ i - 1 ] ; let org = n ; let sum = 0 ; while ( n > 0 ) { let d = n % 10 ; sum += fact [ d ] ; n = parseInt ( n / 10 ) ; } if ( sum == org ) return true ; return false ; } let n = 40585 ; if ( isFactorion ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: d, i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
const TOTAL_BITS = 32 ; function CountBits ( value ) { let count = 0 ; while ( value != 0 ) { count ++ ; value &= value - 1 ; } return count ; } function isPossible ( n ) { let cnt = CountBits ( n ) ; if ( cnt == parseInt ( TOTAL_BITS / 2 ) ) return true ; return false ; } let n = 524280 ; if ( isPossible ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: count, value
Javascript program:
const TEN = 10 ; function updateFreq ( n , freq ) { while ( n ) { let digit = n % TEN ; freq [ digit ] ++ ; n = parseInt ( n / TEN ) ; } } function areAnagrams ( a , b ) { let freqA = new Array ( TEN ) . fill ( 0 ) ; let freqB = new Array ( TEN ) . fill ( 0 ) ; updateFreq ( a , freqA ) ; updateFreq ( b , freqB ) ; for ( let i = 0 ; i < TEN ; i ++ ) { if ( freqA [ i ] != freqB [ i ] ) return false ; } return true ; } let a = 240 , b = 204 ; if ( areAnagrams ( a , b ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: digit, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getArray ( n ) { let ans = [ ] ; let p2 = 1 ; while ( n > 0 ) { if ( n & 1 ) ans . push ( p2 ) ; n >>= 1 ; p2 *= 2 ; } return ans ; } let n = 15 ; let ans = getArray ( n ) ; for ( let i = 0 ; i < ans . length ; i ++ ) document . write ( ans [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i, p2
Iterator variables: i
Javascript program:
M = 3 ; N = 2 ; function getIndex ( n , shuffle ) { for ( i = 0 ; i < 3 ; i ++ ) { if ( shuffle [ i ] [ 0 ] == n ) n = shuffle [ i ] [ 1 ] ; else if ( shuffle [ i ] [ 1 ] == n ) n = shuffle [ i ] [ 0 ] ; } document . write ( n ) ; } var n = 3 ; var shuffle = [ [ 3 , 1 ] , [ 2 , 1 ] , [ 1 , 2 ] ] ; getIndex ( n , shuffle ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function fact ( n ) { let res = 1 ; for ( let i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function nCr ( n , r ) { return fact ( n ) / ( 1 * fact ( r ) * fact ( n - r ) ) ; } function number_of_subsequences ( arr , k , n ) { let s = 0 ; let mp = new Map ( ) ; for ( let 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 ) ; } } for ( let [ key , value ] of mp . entries ( ) ) { s = s + 1 * nCr ( value , k ) ; } return s ; } let arr = [ 1 , 1 , 1 , 1 , 2 , 2 , 2 ] ; let k = 2 ; let n = arr . length ; document . write ( number_of_subsequences ( arr , k , n ) ) ;

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

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minSum ( arr , n ) { let sum = 0 ; arr . sort ( function ( a , b ) { return b - a } ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 4 < 2 ) sum = sum + arr [ i ] ; } return sum ; } let arr = [ 1 , 1 , 10 , 2 , 2 , 2 , 1 ] ; let n = arr . length ; document . write ( minSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countTriplets ( A , B , C ) { let ans = 0 ; for ( let i = 1 ; i <= A ; i ++ ) { for ( let j = 1 ; j <= B ; j ++ ) { for ( let k = 1 ; k <= C ; k ++ ) { if ( i * k > j * j ) ans ++ ; } } } return ans ; } let A , B , C ; A = 3 , B = 2 , C = 2 ; document . write ( countTriplets ( A , B , C ) ) ;

Accumulator variables: ans, i, j, k
Iterator variables: i, j, k
Javascript program:
function getCount ( A , B2 , C ) { let count = 0 ; for ( let i = 1 ; i <= A ; i ++ ) { let j = parseInt ( B2 / i ) + 1 ; if ( C >= j ) count = ( count + C - j + 1 ) ; if ( A >= j && C >= i ) count = ( count + ( C - i + 1 ) * ( A - j + 1 ) ) ; if ( A >= j ) A = j - 1 ; } return count ; } function countTriplets ( A , B , ) { let ans = 0 ; for ( let i = 1 ; i <= B ; i ++ ) { ans = ( ans + getCount ( A , i * i , C ) ) ; } return ans ; } let A , B , C ; A = 3 , B = 2 , C = 2 ; document . write ( countTriplets ( A , B , C ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function getSum ( n ) { let sum = 0 ; let k = parseInt ( Math . sqrt ( n ) ) ; for ( let i = 1 ; i <= k ; i ++ ) { sum += Math . floor ( n / i ) ; } sum *= 2 ; sum -= Math . pow ( k , 2 ) ; return sum ; } let n = 5 ; document . write ( getSum ( n ) ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countUnsetBits ( n ) { var cnt = 0 ; for ( var i = 1 ; i <= n ; i ++ ) { var temp = i ; while ( temp ) { if ( temp % 2 == 0 ) cnt ++ ; temp = parseInt ( temp / 2 ) ; } } return cnt ; } var n = 5 ; document . write ( countUnsetBits ( n ) ) ;

Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function graphExists ( a , n ) { while ( 1 ) { a . sort ( ( a , b ) => b - a ) if ( a [ 0 ] == 0 ) return true ; var v = a [ 0 ] ; a . shift ( ) ; if ( v > a . length ) return false ; for ( var i = 0 ; i < v ; i ++ ) { a [ i ] -- ; if ( a [ i ] < 0 ) return false ; } } } var a = [ 3 , 3 , 3 , 3 ] ; var n = a . length ; graphExists ( a , n ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function negProdSubArr ( arr , n ) { let positive = 1 , negative = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) arr [ i ] = 1 ; else arr [ i ] = - 1 ; if ( i > 0 ) arr [ i ] *= arr [ i - 1 ] ; if ( arr [ i ] == 1 ) positive ++ ; else negative ++ ; } return ( positive * negative ) ; } let arr = [ 5 , - 4 , - 3 , 2 , - 5 ] ; let n = arr . length ; document . write ( negProdSubArr ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, negative, positive
Iterator variables: i
Javascript program:
function sum ( n ) { var sum = ( n * ( n + 1 ) ) / 2 ; return sum ; } function repeatedSum ( n , k ) { for ( i = 0 ; i < k ; i ++ ) { n = sum ( n ) ; } return n ; } var n = 2 , k = 2 ; document . write ( repeatedSum ( n , k ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isDivisible ( n ) { var temp = n ; var sum = 0 ; while ( n != 0 ) { var digit = parseInt ( n % 10 ) ; sum += digit ; n = parseInt ( n / 10 ) ; } n = temp ; while ( n != 0 ) { var digit = parseInt ( n % 10 ) ; if ( sum % digit != 0 ) return false ; n = parseInt ( n / 10 ) ; } return true ; } var n = 123 ; if ( isDivisible ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: sum
Javascript program:
function getResult ( n ) { var st = n . toString ( ) ; var sum = 0 var length = st . length ; for ( var i = 0 ; i < st . length ; i ++ ) { sum = sum + Number ( st [ i ] ) } for ( var i = 0 ; i < st . length ; i ++ ) { if ( sum % Number ( st [ i ] ) != 0 ) { return ' ' } else { return ' ' ; } } } var n = 123 ; document . write ( getResult ( n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
const N = 100005 ; let lpf = new Array ( N ) ; function least_prime_factor ( ) { for ( let i = 2 ; i < N ; i ++ ) if ( ! lpf [ i ] ) for ( let j = i ; j < N ; j += i ) if ( ! lpf [ j ] ) lpf [ j ] = i ; } function Mobius ( n ) { let mobius = new Array ( N ) ; for ( let i = 1 ; i < N ; i ++ ) { if ( i == 1 ) mobius [ i ] = 1 ; else { if ( lpf [ parseInt ( i / lpf [ i ] ) ] == lpf [ i ] ) mobius [ i ] = 0 ; else mobius [ i ] = - 1 * mobius [ parseInt ( i / lpf [ i ] ) ] ; } } for ( let i = 1 ; i <= n ; i ++ ) document . write ( mobius [ i ] + " " ) ; } let n = 5 ; least_prime_factor ( ) ; Mobius ( n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var DIGITS = 4 , MIN = 1000 , MAX = 9999 ; function getBest ( prev , cur ) { var maximum = Math . max ( MIN , prev ) ; for ( var i = maximum ; i <= MAX ; i ++ ) { var cnt = 0 ; var a = i ; var b = cur ; for ( var k = 0 ; k < DIGITS ; k ++ ) { if ( a % 10 != b % 10 ) cnt += 1 ; a = parseInt ( a / 10 ) ; b = parseInt ( b / 10 ) ; } if ( cnt <= 1 ) return i ; } return - 1 ; } function getList ( arr , n ) { var myList = [ ] ; var i , cur ; var possible = true ; myList . push ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) { cur = arr [ i ] ; myList . push ( getBest ( myList [ myList . length - 1 ] , cur ) ) ; if ( myList [ myList . length - 1 ] == - 1 ) { possible = false ; break ; } } if ( possible ) { for ( i = 1 ; i < myList . length ; i ++ ) document . write ( myList [ i ] + " " ) ; } else document . write ( " " ) ; } var arr = [ 1095 , 1094 , 1095 ] ; var n = arr . length ; getList ( arr , n ) ;

Index/key variables: i
Accumulator variables: cnt, i, k
Iterator variables: i, k
Boolean variables: possible
Javascript program:
function countFactors ( n , p ) { let pwr = 0 ; while ( n > 0 && n % p == 0 ) { n /= p ; pwr ++ ; } return pwr ; } function getCount ( l , r , p ) { let cnt = 0 ; for ( let i = l ; i <= r ; i ++ ) { cnt += countFactors ( i , p ) ; } return cnt ; } let l = 2 , r = 8 , p = 2 ; document . write ( getCount ( l , r , p ) ) ;

Accumulator variables: cnt, i, n, pwr
Iterator variables: i
Javascript program:
function getCount ( l , r , p ) { let cnt = 0 ; let val = p ; while ( 1 ) { let a = parseInt ( r / val ) ; let b = parseInt ( ( l - 1 ) / val ) ; val *= p ; if ( a - b ) { cnt += ( a - b ) ; } else break ; } return cnt ; } let l = 2 , r = 8 , p = 2 ; document . write ( getCount ( l , r , p ) ) ;

Accumulator variables: cnt, val
Javascript program:
function topsyTurvy ( str ) { for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' str [ i ] == ' ' str [ i ] == ' ' str [ i ] == ' ' str [ i ] == ' ' str [ i ] == ' ' ) { return false ; } } return true ; } var str = " " ; if ( topsyTurvy ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSubSeq ( arr , n , k ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { count ++ ; } } return ( Math . pow ( 2 , count ) - 1 ) ; } let arr = [ 1 , 2 , 3 , 6 ] ; let n = arr . length ; let k = 3 ; document . write ( countSubSeq ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
const MAX = 1000001 ; function countNum ( N , K ) { let sumPF = new Array ( MAX ) . fill ( 0 ) ; for ( let i = 2 ; i < N ; i ++ ) { if ( sumPF [ i ] == 0 ) { for ( let j = i ; j < N ; j += i ) { sumPF [ j ] += i ; } } } let count = 0 ; for ( let i = 2 ; i < N ; i ++ ) { if ( sumPF [ i ] == K ) count ++ ; } return count ; } let N = 20 , K = 7 ; document . write ( countNum ( N , K ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
const MAX = 100000 ; let prime = new Array ( MAX + 1 ) . fill ( true ) ; function SieveOfEratosthenes ( ) { for ( let p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= MAX ; i += p ) prime [ i ] = false ; } } } function smallestPrime ( d ) { let l = Math . pow ( 10 , d - 1 ) ; let r = Math . pow ( 10 , d ) - 1 ; for ( let i = l ; i <= r ; i ++ ) { if ( prime [ i ] ) { return i ; } } return - 1 ; } function largestPrime ( d ) { let l = Math . pow ( 10 , d - 1 ) ; let r = Math . pow ( 10 , d ) - 1 ; for ( let i = r ; i >= l ; i -- ) { if ( prime [ i ] ) { return i ; } } return - 1 ; } SieveOfEratosthenes ( ) ; let queries = [ 2 , 5 ] ; let q = queries . length ; for ( let i = 0 ; i < q ; i ++ ) { document . write ( smallestPrime ( queries [ i ] ) + " " + largestPrime ( queries [ i ] ) + " " ) ; }

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function printMatrix ( n , k ) { for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( i == j ) document . write ( k + " " ) ; else document . write ( " " ) ; } document . write ( " " ) ; } } var n = 3 , k = 7 ; printMatrix ( n , k ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findNthNumber ( A , B , N ) { var sum = 0 ; for ( i = 2 ; i < N ; i ++ ) { sum = A + B ; A = B ; B = sum ; } return sum ; } var A = 5 , B = 7 , N = 10 ; document . write ( findNthNumber ( A , B , N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isPossible ( arr , p , n , m ) { var sum = 0 ; for ( var i = 0 ; i < p ; i ++ ) sum += arr [ i ] ; if ( sum == ( n * m ) ) return true ; return false ; } var n = 3 , m = 4 ; var arr = [ 6 , 3 , 2 , 1 ] ; var p = arr . length ; if ( isPossible ( arr , p , n , m ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function MinStep ( a , n ) { let positive = 0 , negative = 0 , zero = 0 ; let step = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { zero ++ ; } else if ( a [ i ] < 0 ) { negative ++ ; step = step + ( - 1 - a [ i ] ) ; } else { positive ++ ; step = step + ( a [ i ] - 1 ) ; } } if ( negative % 2 == 0 ) { step = step + zero ; } else { if ( zero > 0 ) { step = step + zero ; } else { step = step + 2 ; } } return step ; } let a = [ 0 , - 2 , - 1 , - 3 , 4 ] ; let n = a . length ; document . write ( MinStep ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, negative, positive, zero
Iterator variables: i
Javascript program:
function sum ( n ) { var sum = 0 ; while ( n > 0 ) { sum = sum + n % 10 ; n = parseInt ( n / 10 ) ; } return sum ; } function firstN ( n ) { var num = 19 , cnt = 1 ; while ( cnt != n ) { if ( sum ( num ) == 10 ) { document . write ( num + " " ) ; cnt ++ ; } num += 9 ; } } var n = 10 ; firstN ( n ) ;

Accumulator variables: cnt, num
Javascript program:
function sumOfLastDig ( n , m ) { let sum = 0 , k ; k = parseInt ( n / m ) ; let arr = new Array ( 10 ) ; for ( let i = 0 ; i < 10 ; i ++ ) { arr [ i ] = m * ( i + 1 ) % 10 ; sum += arr [ i ] ; } let rem = k % 10 ; let ans = parseInt ( k / 10 ) * sum ; for ( let i = 0 ; i < rem ; i ++ ) { ans += arr [ i ] ; } return ans ; } let n = 100 , m = 3 ; document . write ( sumOfLastDig ( n , m ) ) ;

Index/key variables: i
Accumulator variables: ans, i, sum
Iterator variables: i
Javascript program:
function countSum ( arr , n ) { let NumberOfOdds = 0 , NumberOfEvens = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] & 1 ) NumberOfOdds ++ ; NumberOfEvens = n - NumberOfOdds ; let NumberOfOddSubsequences = ( 1 << NumberOfEvens ) * ( 1 << ( NumberOfOdds - 1 ) ) ; let NumberOfEvenSubsequences = ( 1 << n ) - 1 - NumberOfOddSubsequences ; return [ NumberOfEvenSubsequences , NumberOfOddSubsequences ] ; } let arr = [ 1 , 2 , 2 , 3 ] ; let n = arr . length ; let ans = countSum ( arr , n ) ; document . write ( " " + ans [ 0 ] ) ; document . write ( " " + ans [ 1 ] ) ;

Index/key variables: i
Accumulator variables: NumberOfOdds, 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 ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function nextPrime ( N ) { if ( N <= 1 ) return 2 ; let prime = N ; let found = false ; while ( ! found ) { prime ++ ; if ( isPrime ( prime ) ) found = true ; } return prime ; } let N = 3 ; document . write ( nextPrime ( N ) ) ;

Accumulator variables: prime
Iterator variables: i
Boolean variables: found
Javascript program:
function Survives ( n ) { let i ; for ( let i = 2 ; ; i ++ ) { if ( i > n ) return true ; if ( n % i == 0 ) return false ; n -= parseInt ( n / i ) ; } } let n = 17 ; if ( Survives ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i, n
Iterator variables: i
Javascript program:
function find_Solution ( x , n ) { let sum = x , e = 2 , o = 1 , p = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { p += 2 ; sum += ( o / e ) * ( Math . pow ( x , p ) / p ) ; o = o * ( o + 2 ) ; e = e * ( e + 2 ) ; } document . write ( sum . toFixed ( 10 ) ) ; } let x = - 0.5 ; if ( Math . abs ( x ) >= 1 ) { document . write ( " " ) ; } let n = 8 ; find_Solution ( x , n ) ;

Accumulator variables: i, p, sum
Iterator variables: i
Javascript program:
function rightmostNonZero ( a , n ) { var c5 = 0 ; for ( i = 0 ; i < n ; i ++ ) { while ( a [ i ] > 0 && a [ i ] % 5 == 0 ) { a [ i ] /= 5 ; c5 ++ ; } } for ( i = 0 ; i < n ; i ++ ) { while ( c5 != 0 && a [ i ] > 0 && ( a [ i ] & 1 ) == 0 ) { a [ i ] >>= 1 ; c5 -- ; } } var ans = 1 ; for ( i = 0 ; i < n ; i ++ ) { ans = ( ans * a [ i ] % 10 ) % 10 ; } if ( c5 != 0 ) ans = ( ans * 5 ) % 10 ; if ( ans != 0 ) return ans ; return - 1 ; } var a = [ 7 , 42 , 11 , 64 ] ; var n = a . length ; document . write ( rightmostNonZero ( a , n ) ) ;

Index/key variables: i
Accumulator variables: c5, i
Iterator variables: i
Javascript program:
function findRemainder ( n ) { let l = n % 10 ; while ( n >= 10 ) n /= 10 ; let f = n ; let remainder = f % l ; document . write ( Math . floor ( remainder ) ) ; } let n = 5223 ; findRemainder ( n ) ;

Accumulator variables: n
Javascript program:
function increaseInVol ( l , b , h ) { let percentInc = ( 1 + ( l / 100 ) ) * ( 1 + ( b / 100 ) ) * ( 1 + ( h / 100 ) ) ; percentInc -= 1 ; percentInc *= 100 ; return percentInc ; } let l = 50 , b = 20 , h = 10 ; document . write ( increaseInVol ( l , b , h ) + " " ) ;

Accumulator variables: percentInc
Javascript program:
function TwentyoneMatchstick ( arr , N ) { for ( var i = 0 ; i < N ; i += 1 ) { document . write ( 5 - arr [ i ] + " " ) ; } document . write ( " " ) ; } var arr = [ 3 , 4 , 2 , 2 ] ; var N = arr . length ; TwentyoneMatchstick ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i