codeparrot/xlcost-text-to-code huggingface dataset:
Map every character of one string to another such that all occurrences are mapped to the same character | Javascript implementation of the approach ; Function that returns true if the mapping is possible ; Both the strings are of un - equal lengths ; To store the frequencies of the characters in both the string ; Update frequencies of the characters ; For every character of s1 ; If current character is not present in s1 ; Find a character in s2 that has frequency equal to the current character 's  frequency in s1 ; If such character is found ; Set the frequency to - 1 so that it doesn 't get picked again ; Set found to true ; If there is no character in s2 that could be mapped to the current character in s1 ; Driver code
var MAX = 26 ; function canBeMapped ( s1 , l1 , s2 , l2 ) { if ( l1 != l2 ) return false ; var freq1 = Array ( MAX ) . fill ( 0 ) ; var freq2 = Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < l1 ; i ++ ) freq1 [ s1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( var i = 0 ; i < l2 ; i ++ ) freq2 [ s2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( var i = 0 ; i < MAX ; i ++ ) { if ( freq1 [ i ] == 0 ) continue ; var found = false ; for ( var j = 0 ; j < MAX ; j ++ ) { if ( freq1 [ i ] == freq2 [ j ] ) { freq2 [ j ] = - 1 ; found = true ; break ; } } if ( ! found ) return false ; } return true ; } var s1 = " " ; var s2 = " " ; var l1 = s1 . length ; var l2 = s2 . length ; if ( canBeMapped ( s1 , l1 , s2 , l2 ) ) document . write ( " " ) ; else document . write ( " " ) ;
Distinct strings such that they contains given strings as sub | Set to store strings and avoid duplicates ; Recursive function to generate the required strings ; If current string is part of the result ; Insert it into the set ; If character from str1 can be chosen ; If character from str2 can be chosen ; Function to print the generated strings from the set ; Driver code
let stringSet = new Set ( ) ; function find_permutation ( str1 , str2 , len1 , len2 , i , j , res ) { if ( res . length == len1 + len2 ) { stringSet . add ( res ) ; return ; } if ( i < len1 ) find_permutation ( str1 , str2 , len1 , len2 , i + 1 , j , res + str1 [ i ] ) ; if ( j < len2 ) find_permutation ( str1 , str2 , len1 , len2 , i , j + 1 , res + str2 [ j ] ) ; } function print_set ( ) { for ( let s of stringSet . values ( ) ) { document . write ( s + " " ) ; } } let str1 = " " , str2 = " " ; let len1 = str1 . length ; let len2 = str2 . length ; find_permutation ( str1 , str2 , len1 , len2 , 0 , 0 , " " ) ; print_set ( ) ;
Generate all possible strings such that char at index i is either str1 [ i ] or str2 [ i ] | Recursive function to generate the required strings ; If length of the current string is equal to the length of the given strings then the current string is part of the result ; Choosing the current character from the string a ; Choosing the current character from the string b ; Driver code ; Third argument is an empty string that we will be appended in the recursion calls Fourth arguments is the length of the resultant string so far
function generateStr ( a , b , s , count , len ) { if ( count == len ) { document . write ( s + " " ) ; return ; } generateStr ( a . substring ( 1 ) , b . substring ( 1 ) , s + a [ 0 ] , count + 1 , len ) ; generateStr ( a . substring ( 1 ) , b . substring ( 1 ) , s + b [ 0 ] , count + 1 , len ) ; } var a = " " , b = " " ; var n = a . length ; generateStr ( a , b , " " , 0 , n ) ;
Count of non | Function to return the count of required non - overlapping sub - strings ; To store the required count ; If "010" matches the sub - string starting at current index i ; If "101" matches the sub - string starting at current index i ; Driver code
function countSubStr ( s , n ) { var count = 0 ; for ( i = 0 ; i < n - 2 ; ) { if ( s [ i ] == ' ' && s [ i + 1 ] == ' ' && s [ i + 2 ] == ' ' ) { count ++ ; i += 3 ; } else if ( s [ i ] == ' ' && s [ i + 1 ] == ' ' && s [ i + 2 ] == ' ' ) { count ++ ; i += 3 ; } else { i ++ ; } } return count ; } var s = " " ; var n = s . length ; document . write ( countSubStr ( s , n ) ) ;
Find distinct characters in distinct substrings of a string | Function to return the count of distinct characters in all the distinct sub - strings of the given string ; To store all the sub - strings ; To store the current sub - string ; To store the characters of the current sub - string ; If current sub - string hasn 't  been stored before ; Insert it into the set ; Update the count of distinct characters ; Driver code
function countTotalDistinct ( str ) { let cnt = 0 ; let items = new Set ( ) ; for ( let i = 0 ; i < str . length ; ++ i ) { let temp = " " ; let ans = new Set ( ) ; for ( let j = i ; j < str . length ; ++ j ) { temp = temp + str [ j ] ; ans . add ( str [ j ] ) ; if ( ! items . has ( temp ) ) { items . add ( temp ) ; cnt += ans . size ; } } } return cnt ; } let str = " " ; document . write ( countTotalDistinct ( str ) ) ;
Partition the string in two parts such that both parts have at least k different characters | Function to find the partition of the string such that both parts have at least k different characters ; Length of the string ; To check if the current character is already found ; Count number of different characters in the left part ; If current character is not already found , increase cnt by 1 ; If count becomes equal to k , we 've  got the first part, therefore,  store current index and break the loop ; Increment i by 1 ; Clear the map ; Assign cnt as 0 ; If the current character is not already found , increase cnt by 1 ; If cnt becomes equal to k , the second part also have k different characters so break it ; If the second part has less than k different characters , then print " Not ▁ Possible " ; Otherwise print both parts ; Driver code ; Function call
function division_of_string ( str , k ) { let n = str . length ; let has = new Map ( ) ; let ans = 0 , cnt = 0 , i = 0 ; while ( i < n ) { if ( ! has . has ( str [ i ] ) ) { cnt ++ ; has . set ( str [ i ] , true ) ; } if ( cnt == k ) { ans = i ; break ; } i ++ ; } i ++ ; has . clear ( ) ; cnt = 0 ; while ( i < n ) { if ( ! has . has ( str [ i ] ) ) { cnt ++ ; has . set ( str [ i ] , true ) ; } if ( cnt == k ) { break ; } i ++ ; } if ( cnt < k ) { document . write ( " " + " " ) ; } else { i = 0 ; while ( i <= ans ) { document . write ( str [ i ] ) ; i ++ ; } document . write ( " " + " " ) ; while ( i < n ) { document . write ( str [ i ] ) ; i ++ ; } document . write ( " " + " " ) ; } document . write ( " " + " " ) ; } let str = " " ; let k = 4 ; division_of_string ( str . split ( ' ' ) , k ) ;
Remove first adjacent pairs of similar characters until possible | Function to remove adjacent duplicates ; Iterate for every character in the string ; If ans string is empty or its last character does not match with the current character then append this character to the string ; Matches with the previous one ; Return the answer ; Driver Code
function removeDuplicates ( S ) { var ans = " " ; for ( i = 0 ; i < S . length ; i ++ ) { if ( ans . length == 0 || ans . charAt ( ans . length - 1 ) != S . charAt ( i ) ) ans += S . charAt ( i ) ; else if ( ans . charAt ( ans . length - 1 ) == S . charAt ( i ) ) ans = ans . substring ( 0 , ans . length - 1 ) ; } return ans ; } var str = " " ; document . write ( removeDuplicates ( str ) ) ;
Reverse individual words with O ( 1 ) extra space | Javascript implementation of the approach ; Function to resturn the string after reversing the individual words ; Pointer to the first character of the first word ; If the current word has ended ; Pointer to the last character of the current word ; Reverse the current word ; Pointer to the first character of the next word ; Driver code
function swap ( str , i , j ) { let sb = str . split ( " " ) ; sb [ i ] = str [ j ] ; sb [ j ] = str [ i ] ; return sb . join ( " " ) ; } function reverseWords ( str ) { let start = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' i == str . length - 1 ) { let end ; if ( i == str . length - 1 ) end = i ; else end = i - 1 ; while ( start < end ) { str = swap ( str , start , end ) ; start ++ ; end -- ; } start = i + 1 ; } } return str ; } let str = " " ; document . write ( reverseWords ( str ) ) ;
Reverse the Words of a String using Stack | Function to reverse the words of the given sentence ; Create an empty character array stack ; Push words into the stack ; Get the words in reverse order ; Driver code
function reverse ( k ) { let s = [ ] ; let token = k . split ( " " ) ; for ( let i = 0 ; i < token . length ; i ++ ) { s . push ( token [ i ] ) ; } while ( s . length > 0 ) { document . write ( s [ s . length - 1 ] + " " ) ; s . pop ( ) ; } } let k = " " ; reverse ( k ) ;
Count of substrings which contains a given character K times | Function to count the number of substrings which contains the character C exactly K times ; left and right counters for characters on both sides of substring window ; left and right pointer on both sides of substring window ; Initialize the frequency ; Result and length of string ; Initialize the left pointer ; Initialize the right pointer ; Traverse all the window substrings ; Counting the characters on leftSide of substring window ; Counting the characters on rightSide of substring window ; Add the possible substrings on both sides to result ; Setting the frequency for next substring window ; Reset the left , right counters ; Driver code
function countSubString ( s , c , k ) { var leftCount = 0 , rightCount = 0 ; var left = 0 , right = 0 ; var freq = 0 ; var result = 0 , len = s . length ; while ( s [ left ] !== c && left < len ) { left ++ ; leftCount ++ ; } right = left + 1 ; while ( freq !== k - 1 && right - 1 < len ) { if ( s [ right ] === c ) freq ++ ; right ++ ; } while ( left < len && right - 1 < len ) { while ( s [ left ] !== c && left < len ) { left ++ ; leftCount ++ ; } while ( right < len && s [ right ] !== c ) { if ( s [ right ] === c ) freq ++ ; right ++ ; rightCount ++ ; } result = result + ( leftCount + 1 ) * ( rightCount + 1 ) ; freq = k - 1 ; leftCount = 0 ; rightCount = 0 ; left ++ ; right ++ ; } return result ; } var s = " " ; var c = " " ; var k = 2 ; document . write ( countSubString ( s , c , k ) ) ;
Count of sub | Function to return the total required sub - sequences ; Find ways for all values of x ; x + 1 ; Removing all unnecessary digits ; Prefix Sum Array for X + 1 digit ; Sum of squares ; Previous sum of all possible pairs ; To find sum of multiplication of all possible pairs ; To prevent overcounting ; Adding ways for all possible x ; Driver code
function solve ( test , MOD ) { let size = test . length ; let total = 0 ; for ( let i = 0 ; i <= 8 ; i ++ ) { let x = i ; let y = i + 1 ; let newtest = " " ; for ( let j = 0 ; j < size ; j ++ ) { if ( test [ j ] . charCodeAt ( 0 ) == x + 48 || test [ j ] . charCodeAt ( 0 ) == y + 48 ) { newtest += test [ j ] ; } } if ( newtest . length > 0 ) { let size1 = newtest . length ; let prefix = new Array ( size1 ) ; for ( let j = 0 ; j < size1 ; j ++ ) { prefix [ j ] = 0 ; if ( newtest [ j ] . charCodeAt ( 0 ) == y + 48 ) { prefix [ j ] ++ ; } } for ( let j = 1 ; j < size1 ; j ++ ) { prefix [ j ] += prefix [ j - 1 ] ; } let count = 0 ; let firstcount = 0 ; let ss = 0 ; let prev = 0 ; for ( let j = 0 ; j < size1 ; j ++ ) { if ( newtest [ j ] . charCodeAt ( 0 ) == x + 48 ) { count ++ ; firstcount ++ ; } else { ss += count * count ; let pairsum = Math . floor ( ( firstcount * firstcount - ss ) / 2 ) ; let temp = pairsum ; pairsum -= prev ; prev = temp ; let secondway = prefix [ size1 - 1 ] ; if ( j != 0 ) secondway -= prefix [ j - 1 ] ; let answer = count * ( count - 1 ) * secondway * ( secondway - 1 ) ; answer = Math . floor ( answer / 4 ) ; answer += Math . floor ( ( pairsum * secondway * ( secondway - 1 ) ) / 2 ) ; total += answer ; count = 0 ; } } } } return total ; } let test = " " ; let MOD = 1000000007 ; document . write ( solve ( test , MOD ) ) ;
Find if it is possible to make a binary string which contanins given number of "0" , "1" , "01" and "10" as sub sequences | Function that returns true if it is possible to make a binary string consisting of l 0 ' s , ▁ m ▁ 1' s , x "01" sub - sequences and y "10" sub - sequences ; Driver code
function isPossible ( l , m , x , y ) { if ( l * m == x + y ) return true ; return false ; } let l = 3 , m = 2 , x = 4 , y = 2 ; if ( isPossible ( l , m , x , y ) ) document . write ( " " ) ; else document . write ( " " ) ;
Count pairs of characters in a string whose ASCII value difference is K | JavaScript implementation of the approach ; Function to return the count of required pairs of characters ; Length of the string ; To store the frequency of each character ; Update the frequency of each character ; To store the required count of pairs ; If ascii value difference is zero ; If there exists similar characters more than once ; If there exits characters with ASCII value difference as k ; Return the required count ; Driver code
const MAX = 26 ; function countPairs ( str , k ) { var n = str . length ; var freq = new Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { freq [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } var cnt = 0 ; if ( k === 0 ) { for ( var i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] > 1 ) { cnt += ( freq [ i ] * ( freq [ i ] - 1 ) ) / 2 ; } } } else { for ( var i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] > 0 && i + k < MAX && freq [ i + k ] > 0 ) { cnt += freq [ i ] * freq [ i + k ] ; } } } return cnt ; } var str = " " ; var k = 0 ; document . write ( countPairs ( str . split ( " " ) , k ) ) ;
Count of three non | Function that returns true if s [ i ... j ] + s [ k ... l ] + s [ p ... q ] is a palindrome ; Function to return the count of valid sub - strings ; To store the count of required sub - strings ; For choosing the first sub - string ; For choosing the second sub - string ; For choosing the third sub - string ; Check if the concatenation is a palindrome ; Driver code
function isPalin ( i , j , k , l , p , q , s ) { var start = i , end = q ; while ( start < end ) { if ( s [ start ] != s [ end ] ) return false ; start ++ ; if ( start == j + 1 ) start = k ; end -- ; if ( end == p - 1 ) end = l ; } return true ; } function countSubStr ( s ) { var count = 0 ; var n = s . length ; for ( var i = 0 ; i < n - 2 ; i ++ ) { for ( var j = i ; j < n - 2 ; j ++ ) { for ( var k = j + 1 ; k < n - 1 ; k ++ ) { for ( var l = k ; l < n - 1 ; l ++ ) { for ( var p = l + 1 ; p < n ; p ++ ) { for ( var q = p ; q < n ; q ++ ) { if ( isPalin ( i , j , k , l , p , q , s ) ) { count ++ ; } } } } } } } return count ; } var s = " " ; document . write ( countSubStr ( s ) ) ;
Find the sum of the ascii values of characters which are present at prime positions | Function that returns true if n is prime ; Function to return the sum of the ascii values of the characters which are present at prime positions ; To store the sum ; For every character ; If current position is prime then add the ASCII value of the character at the current position ; Driver code
function isPrime ( n ) { if ( n == 0 n == 1 ) return false ; for ( let i = 2 ; i * i <= n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function sumAscii ( str , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPrime ( i + 1 ) ) sum += str . charCodeAt ( i ) ; } return sum ; } let str = " " ; let n = str . length ; document . write ( sumAscii ( str , n ) ) ;
Count the nodes of the tree which make a pangram when concatenated with the sub | JavaScript implementation of the approach ; Function that returns if the string x is a pangram ; Function to return the count of nodes which make pangram with the sub - tree nodes ; Function to perform dfs and update the nodes such that weight [ i ] will store the weight [ i ] concatenated with the weights of all the nodes in the sub - tree ; Driver code ; Weights of the nodes ; Edges of the tree
let graph = new Array ( ) ; for ( let i = 0 ; i < 100 ; i ++ ) { graph . push ( [ ] ) } let weight = new Array ( 100 ) . fill ( 0 ) ; function Pangram ( x ) { let mp = new Map ( ) ; let n = x . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( x [ i ] ) ) { mp . set ( x [ i ] , mp . get ( x [ i ] ) + 1 ) } else { mp . set ( x [ i ] , 1 ) } } if ( mp . size == 26 ) return true ; else return false ; } function countTotalPangram ( n ) { let cnt = 0 ; for ( let i = 1 ; i <= n ; i ++ ) if ( Pangram ( weight [ i ] ) ) cnt ++ ; return cnt ; } function dfs ( node , parent ) { for ( let to of graph [ node ] ) { if ( to == parent ) continue ; dfs ( to , node ) ; weight [ node ] += weight [ to ] ; } } let n = 6 ; weight [ 1 ] = " " ; weight [ 2 ] = " " ; weight [ 3 ] = " " ; weight [ 4 ] = " " ; weight [ 5 ] = " " ; weight [ 6 ] = " " ; graph [ 1 ] . push ( 2 ) ; graph [ 2 ] . push ( 3 ) ; graph [ 2 ] . push ( 4 ) ; graph [ 1 ] . push ( 5 ) ; graph [ 5 ] . push ( 6 ) ; dfs ( 1 , 1 ) ; document . write ( countTotalPangram ( n ) ) ;
Count the nodes of a tree whose weighted string does not contain any duplicate characters | JavaScript implementation of the approach ; Function that returns true if the string contains unique characters ; Function to perform dfs ; If weighted string of the current node contains unique characters ; Weights of the nodes ; Edges of the tree
let cnt = 0 ; let graph = new Array ( ) ; for ( let i = 0 ; i < 100 ; i ++ ) { graph . push ( [ ] ) } let weight = new Array ( 100 ) ; function uniqueChars ( x ) { let mp = new Map ( ) ; let n = x . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( x [ i ] ) ) { mp . set ( x [ i ] , mp . get ( x [ i ] ) + 1 ) } else { mp . set ( x [ i ] , 1 ) } } if ( mp . size == x . length ) return true ; else return false ; } function dfs ( node , parent ) { if ( uniqueChars ( weight [ node ] ) ) cnt += 1 ; for ( let to of graph [ node ] ) { if ( to == parent ) continue ; dfs ( to , node ) ; } } weight [ 1 ] = " " ; weight [ 2 ] = " " ; weight [ 3 ] = " " ; weight [ 4 ] = " " ; weight [ 5 ] = " " ; graph [ 1 ] . push ( 2 ) ; graph [ 2 ] . push ( 3 ) ; graph [ 2 ] . push ( 4 ) ; graph [ 1 ] . push ( 5 ) ; dfs ( 1 , 1 ) ; document . write ( cnt ) ;
Check if a string contains two non overlapping sub | Function that returns true if s contains two non overlapping sub Strings " geek " and " keeg " ; If " geek " and " keeg " are both present in s without over - lapping and " keeg " starts after " geek " ends ; Driver Code
function isValid ( s ) { if ( ( s . indexOf ( " " ) != - 1 ) && ( s . indexOf ( " " , s . indexOf ( " " ) + 4 ) != - 1 ) ) return true ; return false ; } var s = " " ; if ( isValid ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;
Find the last non repeating character in string | Maximum distinct characters possible ; Function to return the last non - repeating character ; To store the frequency of each of the character of the given string ; Update the frequencies ; Starting from the last character ; Current character ; If frequency of the current character is 1 then return the character ; All the characters of the string are repeating ; Driver code
let MAX = 256 ; function lastNonRepeating ( str , n ) { let freq = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) freq [ str [ i ] . charCodeAt ( 0 ) ] ++ ; for ( let i = n - 1 ; i >= 0 ; i -- ) { let ch = str [ i ] ; if ( freq [ ch . charCodeAt ( 0 ) ] == 1 ) return ( " " + ch ) ; } return " " ; } let str = " " ; let n = str . length ; document . write ( lastNonRepeating ( str , n ) ) ;
Minimum number of operations on a binary string such that it gives 10 ^ A as remainder when divided by 10 ^ B | Function to return the minimum number of operations on a binary string such that it gives 10 ^ A as remainder when divided by 10 ^ B ; Initialize result ; Loop through last b digits ; Driver code
function findCount ( s , n , a , b ) { var res = 0 ; for ( var i = 0 ; i < b ; i ++ ) { if ( i == a ) res += ( s [ n - i - 1 ] != ' ' ) ; else res += ( s [ n - i - 1 ] != ' ' ) ; } return res ; } var str = " " ; var N = str . length ; var A = 3 , B = 6 ; document . write ( findCount ( str , N , A , B ) ) ;
Find letter 's position in Alphabet using Bit operation | JavaScript implementation of the approach ; Function to calculate the position of characters ; Performing AND operation with number 31 ; Driver code
const NUM = 31 ; function positions ( str , n ) { for ( i = 0 ; i < n ; i ++ ) { document . write ( ( str [ i ] . charCodeAt ( 0 ) & NUM ) + " " ) ; } } var str = " " ; var n = str . length ; positions ( str , n ) ;
Length of the longest substring that do not contain any palindrome | Function to find the length of the longest substring ; initializing the variables ; checking palindrome of size 2 example : aa ; checking palindrome of size 3 example : aba ; else incrementing length of substring ; max1 = Math . max ( max1 , len + 1 ) ; finding maximum ; if there exits single character then it is always palindrome ; Driver Code
function lenoflongestnonpalindrome ( s ) { let max1 = 1 , len = 0 ; for ( let i = 0 ; i < s . length - 1 ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) len = 0 ; else if ( s [ i + 1 ] == s [ i - 1 ] && i > 0 ) len = 1 ; len ++ ; } if ( max1 == 1 ) return 0 ; else return max1 ; } let s = " " ; document . write ( lenoflongestnonpalindrome ( s ) + " " ) ;
Make lexicographically smallest palindrome by substituting missing characters | Function to return the lexicographically smallest palindrome that can be made from the given string after replacing the required characters ; If characters are missing at both the positions then substitute it with ' a ' ; If only str [ j ] = ' * ' then update it with the value at str [ i ] ; If only str [ i ] = ' * ' then update it with the value at str [ j ] ; If characters at both positions are not equal and != ' * ' then the string cannot be made palindrome ; Return the required palindrome ; Driver code
function makePalindrome ( str ) { var i = 0 , j = str . length - 1 ; while ( i <= j ) { if ( str [ i ] == ' ' && str [ j ] == ' ' ) { str [ i ] = ' ' ; str [ j ] = ' ' ; } else if ( str [ j ] == ' ' ) str [ j ] = str [ i ] ; else if ( str [ i ] == ' ' ) str [ i ] = str [ j ] ; else if ( str [ i ] != str [ j ] ) return " " ; i ++ ; j -- ; } return str . join ( " " ) ; } var str = " " . split ( ' ' ) ; document . write ( makePalindrome ( str ) ) ;
Calculate score for the given binary string | Function to return the score for the given binary string ; Traverse through string character ; Initialize current chunk 's size ; Get current character ; Calculate total chunk size of same characters ; Add / subtract pow ( chunkSize , 2 ) depending upon character ; Return the score ; Driver code
function calcScore ( str ) { var score = 0 ; var len = str . length ; for ( var i = 0 ; i < len ; ) { var chunkSize = 1 ; var currentChar = str [ i ++ ] ; while ( i < len && str [ i ] == currentChar ) { chunkSize ++ ; i ++ ; } if ( currentChar == ' ' ) score += Math . pow ( chunkSize , 2 ) ; else score -= Math . pow ( chunkSize , 2 ) ; } return score ; } var str = " " ; document . write ( calcScore ( str ) ) ;