dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function count9s ( number ) { let n = number . length ; let d = new Array ( 9 ) ; for ( let i = 0 ; i < d . length ; i ++ ) { d [ i ] = 0 ; } d [ 0 ] = 1 ; let result = 0 ; let mod_sum = 0 , continuous_zero = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( number [ i ] - ' ' ) == 0 ) { continuous_zero ++ ; } else { continuous_zero = 0 ; } mod_sum += ( number [ i ] - ' ' ) ; mod_sum %= 9 ; result += d [ mod_sum ] ; d [ mod_sum ] ++ ; result -= continuous_zero ; } return result ; } document . write ( count9s ( " " ) + " " ) ; document . write ( count9s ( " " ) + " " ) ; document . write ( count9s ( " " ) + " " ) ;

Index/key variables: i, mod_sum
Accumulator variables: continuous_zero, i, mod_sum, result
Iterator variables: i
Javascript program:
function maximumNum ( curr_num , res ) { let len1 = curr_num . length ; let len2 = res . length ; if ( len1 == len2 ) { let i = 0 ; while ( curr_num [ i ] == res [ i ] ) i ++ ; if ( curr_num [ i ] < res [ i ] ) return res ; else return curr_num ; } return len1 < len2 ? res : curr_num ; } function extractMaximum ( str ) { let n = str . length ; let curr_num = " " ; let res = " " ; for ( let i = 0 ; i < n ; i ++ ) { while ( i < n && str [ i ] == ' ' ) i ++ ; while ( i < n && ! isNaN ( String ( str [ i ] ) * 1 ) ) { curr_num = curr_num + str [ i ] ; i ++ ; } if ( i == n ) break ; if ( curr_num . length > 0 ) i -- ; res = maximumNum ( curr_num , res ) ; curr_num = " " ; } if ( curr_num . length == 0 && res . length == 0 ) res = res + ' ' ; return maximumNum ( curr_num , res ) ; } let str = " " ; document . write ( extractMaximum ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isDivisible999 ( num ) { let n = num . length ; if ( n == 0 && num [ 0 ] == ' ' ) return true ; if ( n % 3 == 1 ) num = " " + num ; if ( n % 3 == 2 ) num = " " + num ; let gSum = 0 ; for ( let i = 0 ; i < n ; i += 3 ) { group = 0 ; group += ( num . charCodeAt ( i ) - 48 ) * 100 ; group += ( num . charCodeAt ( i + 1 ) - 48 ) * 10 ; group += ( num . charCodeAt ( i + 2 ) - 48 ) ; gSum += group ; } if ( gSum > 1000 ) { num = String ( gSum ) ; n = strlen ( num ) ; gSum = isDivisible999 ( num ) ; } return ( gSum == 999 ) ; } let num = " " ; if ( isDivisible999 ( num ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: gSum, group, i
Iterator variables: i
Javascript program:
let MAX_CHAR = 26 ; function arrangeString ( str ) { let char_count = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) { char_count [ i ] = 0 ; } let sum = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] >= " " && str [ i ] <= " " ) char_count [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; else sum = sum + ( str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; } let res = " " ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) { let ch = String . fromCharCode ( ' ' . charCodeAt ( 0 ) + i ) ; while ( char_count [ i ] -- != 0 ) res = res + ch ; } if ( sum > 0 ) res = res + sum ; return res ; } let str = " " ; document . write ( arrangeString ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function subString ( str , n ) { for ( let len = 1 ; len <= n ; len ++ ) { for ( let i = 0 ; i <= n - len ; i ++ ) { let j = i + len - 1 ; for ( let k = i ; k <= j ; k ++ ) { document . write ( str [ k ] ) ; } document . write ( " " ) ; } } } let str = [ ' ' , ' ' , ' ' ] ; subString ( str , str . length ) ;

Index/key variables: k
Accumulator variables: i, k, len
Iterator variables: i, k, len
Javascript program:
function reverses ( str ) { let inputArray = str . split ( " " ) ; let result = new Array ( inputArray . length ) ; for ( let i = 0 ; i < inputArray . length ; i ++ ) { if ( inputArray [ i ] == ' ' ) { result [ i ] = ' ' ; } } let j = result . length - 1 ; for ( let i = 0 ; i < inputArray . length ; i ++ ) { if ( inputArray [ i ] != ' ' ) { if ( result [ j ] == ' ' ) { j -- ; } result [ j ] = inputArray [ i ] ; j -- ; } } document . write ( ( result ) . join ( " " ) ) ; } reverses ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
var MAX_CHAR = 26 ; function findAndPrintUncommonChars ( str1 , str2 ) { var present = Array ( MAX_CHAR ) ; for ( var i = 0 ; i < MAX_CHAR ; i ++ ) present [ i ] = 0 ; var l1 = str1 . length ; var l2 = str2 . length ; for ( var i = 0 ; i < l1 ; i ++ ) present [ str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = 1 ; for ( var i = 0 ; i < l2 ; i ++ ) { if ( present [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == 1 || present [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == - 1 ) present [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = - 1 ; else present [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = 2 ; } for ( var i = 0 ; i < MAX_CHAR ; i ++ ) if ( present [ i ] == 1 present [ i ] == 2 ) document . write ( ( String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ) + " " ) ; } var str1 = " " ; var str2 = " " ; findAndPrintUncommonChars ( str1 , str2 ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function lengthOfLastWord ( a ) { let len = 0 ; x = a . trim ( ) ; for ( let i = 0 ; i < x . length ; i ++ ) { if ( x [ i ] == ' ' ) { len = 0 ; } else { len ++ ; } } return len ; } input = " " ; document . write ( " " + lengthOfLastWord ( input ) ) ;

Index/key variables: i
Accumulator variables: i, len
Iterator variables: i
Javascript program:
function isVowel ( ch ) { ch = ch . toUpperCase ( ) ; return ch == " " || ch == " " || ch == " " || ch == " " || ch == " " ; } function countVowels ( str ) { var count = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) if ( isVowel ( str [ i ] ) ) ++ count ; return count ; } var str = " " ; document . write ( countVowels ( str ) ) ; document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
x = 32 ; function toggleCase ( a ) { for ( i = 0 ; i < a . length ; i ++ ) { a [ i ] = String . fromCharCode ( a [ i ] . charCodeAt ( 0 ) ^ 32 ) ; } return a . join ( " " ) ; ; } var str = " " ; document . write ( " " ) ; str = toggleCase ( str . split ( ' ' ) ) ; document . write ( str ) ; document . write ( " " ) ; str = toggleCase ( str . split ( ' ' ) ) ; document . write ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function nextGreaterWithSameDigits ( bnum ) { let l = bnum . length ; let i ; for ( i = l - 2 ; i >= 1 ; i -- ) { if ( bnum [ i ] == ' ' && bnum [ i + 1 ] == ' ' ) { let ch = bnum [ i ] ; bnum [ i ] = bnum [ i + 1 ] ; bnum [ i + 1 ] = ch ; break ; } } if ( i == 0 ) document . write ( " " ) ; let j = i + 2 , k = l - 1 ; while ( j < k ) { if ( bnum [ j ] == ' ' && bnum [ k ] == ' ' ) { let ch = bnum [ j ] ; bnum [ j ] = bnum [ k ] ; bnum [ k ] = ch ; j ++ ; k -- ; } else if ( bnum [ i ] == ' ' ) break ; else j ++ ; } return ( bnum ) . join ( " " ) ; } let bnum = " " . split ( " " ) ; document . write ( " " + " " + nextGreaterWithSameDigits ( bnum ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i
Javascript program:
function printRotatedString ( str ) { var len = str . length ; var sb ; for ( i = 0 ; i < len ; i ++ ) { sb = [ ] ; var j = i ; var k = 0 ; for ( k2 = j ; k2 < str . length ; k2 ++ ) { sb . push ( str . charAt ( j ) ) ; k ++ ; j ++ ; } j = 0 ; while ( j < i ) { sb . push ( str . charAt ( j ) ) ; j ++ ; k ++ ; } document . write ( sb . join ( " " ) + " " ) ; } } var str = " " ; printRotatedString ( str ) ;

Accumulator variables: i, j, k, k2
Iterator variables: i, k2
Javascript program:
function isPalindrome ( str ) { let n = str . length ; for ( let i = 0 ; i < n / 2 ; i ++ ) { if ( str [ i ] != str [ n - i - 1 ] ) return false ; } return true ; } function maxLengthNonPalinSubstring ( str ) { let n = str . length ; let ch = str [ 0 ] ; let i = 1 ; for ( i = 1 ; i < n ; i ++ ) { if ( str [ i ] != ch ) { break ; } } if ( i == n ) return 0 ; if ( isPalindrome ( str ) ) return n - 1 ; return n ; } let str = " " ; document . write ( " " + maxLengthNonPalinSubstring ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function moveSpaceInFront ( str ) { let i = str . length - 1 ; for ( let j = i ; j >= 0 ; j -- ) if ( str [ j ] != ' ' ) { let c = str [ i ] ; str [ i ] = str [ j ] ; str [ j ] = c ; i -- ; } } let str = " " . split ( " " ) ; moveSpaceInFront ( str ) ; document . write ( ( str ) . join ( " " ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: j
Javascript program:
function moveSpaceInFront ( str ) { var i = str . length - 1 ; for ( var j = i ; j >= 0 ; j -- ) if ( str [ j ] !== " " ) str [ i -- ] = str [ j ] ; while ( i >= 0 ) str [ i -- ] = " " ; } var str = " " . split ( " " ) ; moveSpaceInFront ( str ) ; document . write ( str . join ( " " ) ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: j
Javascript program:
function isPalindrome ( str ) { let len = str . length ; if ( len == 1 ) return true ; let ptr1 = 0 ; let ptr2 = len - 1 ; while ( ptr2 >= ptr1 ) { if ( str [ ptr1 ] != str [ ptr2 ] ) return false ; ptr1 ++ ; ptr2 -- ; } return true ; } function noOfAppends ( s ) { if ( isPalindrome ( s . split ( " " ) ) ) return 0 ; s = s . substring ( 1 ) ; return 1 + noOfAppends ( s ) ; } let s = " " ; document . write ( noOfAppends ( s ) ) ;

Index/key variables: ptr1, ptr2
Accumulator variables: ptr1, ptr2
Javascript program:
function titleToNumber ( s ) { let result = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { result *= 26 ; result += s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 1 ; } return result ; } document . write ( titleToNumber ( " " ) ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function reversingString ( str , start , end ) { while ( start < end ) { str [ start ] = String . fromCharCode ( str [ start ] . charCodeAt ( 0 ) ^ str [ end ] . charCodeAt ( 0 ) ) ; str [ end ] = String . fromCharCode ( str [ end ] . charCodeAt ( 0 ) ^ str [ start ] . charCodeAt ( 0 ) ) ; str [ start ] = String . fromCharCode ( str [ start ] . charCodeAt ( 0 ) ^ str [ end ] . charCodeAt ( 0 ) ) ; ++ start ; -- end ; } return ( str ) . join ( " " ) ; } let s = " " ; document . write ( reversingString ( s . split ( " " ) , 0 , 12 ) ) ;

Index/key variables: end, start
Javascript program:
function checkEquality ( s ) { return ( s . charAt ( 0 ) == s . charAt ( s . length - 1 ) ) ; } function countSubstringWithEqualEnds ( s ) { var result = 0 ; var n = s . length ; for ( var i = 0 ; i < n ; i ++ ) for ( var len = 1 ; len <= n - i ; len ++ ) if ( checkEquality ( s . substring ( i , i + len ) ) ) result ++ ; return result ; } var s = " " ; document . write ( countSubstringWithEqualEnds ( s ) ) ;

Accumulator variables: i, len, result
Iterator variables: i, len
Javascript program:
function countSubstringWithEqualEnds ( s ) { var result = 0 ; var n = s . length ; for ( i = 0 ; i < n ; i ++ ) for ( j = i ; j < n ; j ++ ) if ( s . charAt ( i ) == s . charAt ( j ) ) result ++ ; return result ; } var s = " " ; document . write ( countSubstringWithEqualEnds ( s ) ) ;

Accumulator variables: i, j, result
Iterator variables: i, j
Javascript program:
let MAX_DIGITS = 6 ; function getValue ( str , i , m ) { if ( i + m > str . length ) { return - 1 ; } let value = 0 ; for ( let j = 0 ; j < m ; j ++ ) { let c = str [ i + j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; if ( c < 0 c > 9 ) { return - 1 ; } value = value * 10 + c ; } return value ; } function findMissingNumber ( str ) { for ( let m = 1 ; m <= MAX_DIGITS ; ++ m ) { let n = getValue ( str , 0 , m ) ; if ( n == - 1 ) { break ; } let missingNo = - 1 ; let fail = false ; for ( let i = m ; i != str . length ; i += 1 + Math . floor ( Math . log10 ( n ) ) ) { if ( ( missingNo == - 1 ) && ( getValue ( str , i , Math . floor ( 1 + Math . log10 ( n + 2 ) ) ) == n + 2 ) ) { missingNo = n + 1 ; n += 2 ; } else if ( getValue ( str , i , Math . floor ( 1 + Math . log10 ( n + 1 ) ) ) == n + 1 ) { n ++ ; } else { fail = true ; break ; } } if ( ! fail ) { return missingNo ; } } return - 1 ; } document . write ( findMissingNumber ( " " ) ) ;

Accumulator variables: i, j, n
Iterator variables: i, j, m
Boolean variables: fail
Javascript program:
function maxRepeating ( str ) { let len = str . length ; let count = 0 ; let res = str [ 0 ] ; for ( let i = 0 ; i < len ; i ++ ) { let cur_count = 1 ; for ( let j = i + 1 ; j < len ; j ++ ) { if ( str [ i ] != str [ j ] ) break ; cur_count ++ ; } if ( cur_count > count ) { count = cur_count ; res = str [ i ] ; } } return res ; } let str = " " ; document . write ( maxRepeating ( str ) ) ;

Index/key variables: i, j
Accumulator variables: cur_count, i, j
Iterator variables: i, j
Javascript program:
function findSum ( str1 , str2 ) { if ( str1 . length > str2 . length ) { let t = str1 ; str1 = str2 ; str2 = t ; } let str = " " ; let n1 = str1 . length , n2 = str2 . length ; str1 = str1 . split ( " " ) . reverse ( ) . join ( " " ) ; str2 = str2 . split ( " " ) . reverse ( ) . join ( " " ) ; let carry = 0 ; for ( let i = 0 ; i < n1 ; i ++ ) { let sum = ( ( str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) + ( str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) + carry ) ; str += String . fromCharCode ( sum % 10 + ' ' . charCodeAt ( 0 ) ) ; carry = Math . floor ( sum / 10 ) ; } for ( let i = n1 ; i < n2 ; i ++ ) { let sum = ( ( str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) + carry ) ; str += String . fromCharCode ( sum % 10 + ' ' . charCodeAt ( 0 ) ) ; carry = Math . floor ( sum / 10 ) ; } if ( carry > 0 ) str += String . fromCharCode ( carry + ' ' . charCodeAt ( 0 ) ) ; str = str . split ( " " ) . reverse ( ) . join ( " " ) ; return str ; } let str1 = " " ; let str2 = " " ; document . write ( findSum ( str1 , str2 ) )

Index/key variables: i
Accumulator variables: i, str
Iterator variables: i
Javascript program:
function isPalindrome ( str ) { let len = str . length ; for ( let i = 0 ; i < len / 2 ; i ++ ) if ( str [ i ] != str [ len - i - 1 ] ) return false ; return true ; } function checkPalindromePair ( vect ) { for ( let i = 0 ; i < vect . length - 1 ; i ++ ) { for ( let j = i + 1 ; j < vect . length ; j ++ ) { let check_str = " " ; check_str = check_str + vect [ i ] + vect [ j ] ; if ( isPalindrome ( check_str ) ) return true ; check_str = vect [ j ] + vect [ i ] ; if ( isPalindrome ( check_str ) ) return true ; } } return false ; } let vect = [ " " , " " , " " , " " , " " , " " ] if ( checkPalindromePair ( vect ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function print ( str1 ) { let str = str1 . split ( " " ) ; document . write ( str [ 0 ] ) ; for ( let i = 1 ; i < str . length ; i ++ ) { if ( ( str [ i ] . charCodeAt ( 0 ) == str [ i - 1 ] . charCodeAt ( 0 ) + 1 ) || ( str [ i ] . charCodeAt ( 0 ) == str [ i - 1 ] . charCodeAt ( 0 ) - 1 ) ) { document . write ( str [ i ] ) ; } else { document . write ( " " + str [ i ] ) ; } } } let str = " " ; print ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function areChractersUnique ( str ) { let checker = 0 ; for ( let i = 0 ; i < str . length ; ++ i ) { let val = ( str [ i ] - ' ' ) ; if ( ( checker & ( 1 << val ) ) > 0 ) return false ; checker |= ( 1 << val ) ; } return true ; } var s = " " ; if ( areChractersUnique ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: checker
Iterator variables: i
Javascript program:
function countWords ( str , len ) { let count = 1 ; if ( len == 1 ) return count ; if ( str [ 0 ] == str [ 1 ] ) count *= 1 ; else count *= 2 ; for ( let j = 1 ; j < len - 1 ; j ++ ) { if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ; else if ( str [ j ] == str [ j - 1 ] str [ j ] == str [ j + 1 ] str [ j - 1 ] == str [ j + 1 ] ) count *= 2 ; else count *= 3 ; } if ( str [ len - 1 ] == str [ len - 2 ] ) count *= 1 ; else count *= 2 ; return count ; } let str = " " ; let len = str . length ; document . write ( countWords ( str , len ) ) ;

Index/key variables: j
Accumulator variables: count, j
Iterator variables: j
Javascript program:
function replaceDig ( x , from , to ) { var result = 0 ; var multiply = 1 ; while ( x > 0 ) { var reminder = x % 10 ; if ( reminder == from ) result = result + to * multiply ; else result = result + reminder * multiply ; multiply *= 10 ; x = parseInt ( x / 10 ) ; } return result ; } function calculateMinMaxSum ( x1 , x2 ) { var minSum = replaceDig ( x1 , 6 , 5 ) + replaceDig ( x2 , 6 , 5 ) ; var maxSum = replaceDig ( x1 , 5 , 6 ) + replaceDig ( x2 , 5 , 6 ) ; document . write ( " " + minSum ) ; document . write ( " " + maxSum ) ; } var x1 = 5466 , x2 = 4555 ; calculateMinMaxSum ( x1 , x2 ) ;

Accumulator variables: multiply
Javascript program:
function qType1 ( l , x , str1 ) { str1 [ l - 1 ] = x ; } function qType2 ( l , r , str1 ) { let freq = new Array ( 27 ) ; for ( let i = 0 ; i < 27 ; i ++ ) { freq [ i ] = 0 ; } for ( let i = l - 1 ; i <= r - 1 ; i ++ ) { freq [ str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let count = 0 ; for ( let j = 0 ; j < 26 ; j ++ ) { if ( freq [ j ] % 2 != 0 ) { count ++ ; } } if ( count <= 1 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let str = " " . split ( " " ) ; let n = str . length ; qType1 ( 4 , ' ' , str ) ; qType2 ( 1 , 4 , str ) ; qType2 ( 2 , 3 , str ) ; qType1 ( 10 , ' ' , str ) ; qType2 ( 10 , 11 , str ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
let max = 1000 ; function getFrequency ( tree , idx , i ) { let sum = 0 ; while ( idx > 0 ) { sum += tree [ idx ] [ i ] ; idx -= ( idx & - idx ) ; } return sum ; } function update ( tree , idx , val , i ) { while ( idx <= max ) { tree [ idx ] [ i ] += val ; idx += ( idx & - idx ) ; } } function qType1 ( tree , l , x , str ) { update ( tree , l , - 1 , str [ l - 1 ] . charCodeAt ( 0 ) - 97 + 1 ) ; str [ l - 1 ] = x ; update ( tree , l , 1 , str [ l - 1 ] . charCodeAt ( 0 ) - 97 + 1 ) ; } function qType2 ( tree , l , r , str ) { let count = 0 ; for ( let i = 1 ; i <= 26 ; i ++ ) { if ( l == 1 ) { if ( getFrequency ( tree , r , i ) % 2 == 1 ) count ++ ; } else { if ( ( getFrequency ( tree , r , i ) - getFrequency ( tree , l - 1 , i ) ) % 2 == 1 ) count ++ ; } } if ( count <= 1 ) document . write ( " " ) ; else document . write ( " " ) ; } function buildBIT ( tree , str , n ) { for ( let i = 0 ; i < n ; i ++ ) update ( tree , i + 1 , 1 , str [ i ] . charCodeAt ( 0 ) - 97 + 1 ) ; } let str = " " . split ( " " ) ; let n = str . length ; let tree = new Array ( max ) ; for ( let i = 0 ; i < tree . length ; i ++ ) { tree [ i ] = new Array ( 27 ) ; for ( let j = 0 ; j < tree [ i ] . length ; j ++ ) { tree [ i ] [ j ] = 0 ; } } buildBIT ( tree , str , n ) ; qType1 ( tree , 4 , ' ' , str ) ; qType2 ( tree , 1 , 4 , str ) ; qType2 ( tree , 2 , 3 , str ) ; qType1 ( tree , 10 , ' ' , str ) ; qType2 ( tree , 10 , 11 , str ) ;

Index/key variables: i, idx, j
Accumulator variables: count, i, idx, j, sum
Iterator variables: i, j
Javascript program:
function findDivision ( str , a , b ) { let len = str . length ; let lr = [ ] ; for ( let i = 0 ; i < len + 1 ; i ++ ) lr . push ( 0 ) ; lr [ 0 ] = ( str [ 0 ] - ' ' ) % a ; for ( let i = 1 ; i < len ; i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str . charCodeAt ( i ) ) ) % a ; let rl = [ ] ; for ( let i = 0 ; i < len + 1 ; i ++ ) rl . push ( 0 ) ; rl [ len - 1 ] = ( str . charCodeAt ( len - 1 ) ) % b ; let power10 = 10 ; for ( let i = len - 2 ; i >= 0 ; i -- ) { rl [ i ] = ( rl [ i + 1 ] + ( str . charCodeAt ( i ) ) * power10 ) % b ; power10 = ( power10 * 10 ) % b ; } for ( let i = 0 ; i < len - 1 ; i ++ ) { if ( lr [ i ] != 0 ) continue ; if ( rl [ i + 1 ] == 0 ) { document . write ( " " ) ; for ( let k = 0 ; k <= i ; k ++ ) document . write ( str [ k ] ) ; document . write ( " " ) ; for ( let k = i + 1 ; k < len ; k ++ ) document . write ( str [ k ] ) ; return ; } } document . write ( " " ) ; } let str = " " ; let a = 12 , b = 3 ; findDivision ( str , a , b ) ;

Index/key variables: i, k
Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
function findTwoscomplement ( str ) { var n = str . length ; var i ; for ( i = n - 1 ; i >= 0 ; i -- ) if ( str . charAt ( i ) == ' ' ) break ; if ( i == - 1 ) return " " + str ; for ( k = i - 1 ; k >= 0 ; k -- ) { if ( str . charAt ( k ) == ' ' ) str = str . substring ( 0 , k ) + " " + str . substring ( k + 1 , str . length ) ; else str = str . substring ( 0 , k ) + " " + str . substring ( k + 1 , str . length ) ; } return str . toString ( ) ; } var str = " " ; document . write ( findTwoscomplement ( str ) ) ;

Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
function isequal ( str ) { let n = str . length ; let num = 0 , x = 1 , i = n - 1 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( ' ' <= str [ i ] && str [ i ] <= ' ' ) { num = ( str [ i ] - ' ' ) * x + num ; x = x * 10 ; if ( num >= n ) return false ; } else break ; } return num == i + 1 ; } let str = " " ; if ( isequal ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function kAnagrams ( str1 , str2 , k ) { let flag = 0 ; let list = [ ] ; if ( str1 . length != str2 . length ) { return false ; } let arr1 = str1 . split ( ' ' ) ; let arr2 = str2 . split ( ' ' ) ; arr1 . sort ( ) ; arr2 . sort ( ) ; for ( let i = 0 ; i < str1 . length ; i ++ ) { if ( arr1 [ i ] != arr2 [ i ] ) { list . push ( arr2 [ i ] ) ; } } if ( list . length <= k ) flag = 1 ; if ( flag == 1 ) return true ; else return false ; } let str1 = " " ; let str2 = " " ; let k = 2 ; kAnagrams ( str1 , str2 , k ) ; if ( kAnagrams ( str1 , str2 , k ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countToMake0lternate ( s ) { let result = 0 ; for ( let i = 0 ; i < ( s . length - 1 ) ; i ++ ) if ( s [ i ] == s [ i + 1 ] ) return result ; } document . write ( countToMake0lternate ( " " ) + " " ) ; document . write ( countToMake0lternate ( " " ) + " " ) ; document . write ( countToMake0lternate ( " " ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkString ( str , k ) { let n = str . length ; if ( n % k != 0 ) return false ; let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i += k ) { if ( mp . has ( str . substring ( i , i + k ) ) ) mp . set ( str . substring ( i , i + k ) , mp . get ( str . substring ( i , i + k ) ) + 1 ) ; else mp . set ( str . substring ( i , i + k ) , 1 ) ; } if ( mp . size == 1 ) return true ; if ( mp . size != 2 ) { return false ; } for ( let [ key , value ] of mp . entries ( ) ) { if ( value == ( Math . floor ( n / k ) - 1 ) value == 1 ) return true ; } return false ; } if ( checkString ( " " , 2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX_CHAR = 26 ; function sortByPattern ( str , pat ) { let count = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) { count [ i ] = 0 ; } for ( let i = 0 ; i < str . length ; i ++ ) { count [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let index = 0 ; for ( let i = 0 ; i < pat . length ; i ++ ) { for ( let j = 0 ; j < count [ pat [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; j ++ ) { str [ index ++ ] = pat [ i ] ; } } } let pat = " " . split ( " " ) ; let str = " " . split ( " " ) ; sortByPattern ( str , pat ) ; document . write ( ( str ) . join ( " " ) ) ;

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