codeparrot/xlcost-text-to-code huggingface dataset:
Find the k | Function to find the Kth String in lexicographical order which consists of N - 2 xs and 2 ys ; Iterate for all possible positions of eft most Y ; If i is the left most position of Y ; Put Y in their positions ; Driver code ; Function call
function kth_String ( n , k ) { for ( i = n - 2 ; i >= 0 ; i -- ) { if ( k <= ( n - i - 1 ) ) { for ( j = 0 ; j < n ; j ++ ) { if ( j == i j == n - k ) document . write ( ' ' ) ; else document . write ( ' ' ) ; } break ; } k -= ( n - i - 1 ) ; } } var n = 5 , k = 7 ; kth_String ( n , k ) ;
Transform string str1 into str2 by taking characters from string str3 | Function to check whether str1 can be transformed to str2 ; To store the frequency of characters of String str3 ; Declare two pointers & flag ; Traverse both the String and check whether it can be transformed ; If both pointers point to same characters increment them ; If the letters don 't match check  if we can find it in String C ; If the letter is available in String str3 , decrement it 's  frequency & increment the ptr2 ; If letter isn 't present in str3[]  set the flag to false and break ; If the flag is true and both pointers points to their end of respective Strings then it is possible to transformed str1 into str2 , otherwise not . ; Driver Code ; Function Call
function convertString ( str1 , str2 , str3 ) { let freq = new Map ( ) ; for ( let i = 0 ; i < str3 . length ; i ++ ) { if ( freq . has ( str3 [ i ] ) ) freq . set ( str3 [ i ] , freq . get ( str3 [ i ] ) + 1 ) ; else freq . set ( str3 [ i ] , 1 ) ; } let ptr1 = 0 ; let ptr2 = 0 ; let flag = true ; while ( ptr1 < str1 . length && ptr2 < str2 . length ) { if ( str1 [ ptr1 ] == str2 [ ptr2 ] ) { ptr1 ++ ; ptr2 ++ ; } else { if ( freq . has ( str3 [ ptr2 ] ) ) if ( freq . get ( str3 [ ptr2 ] ) > 0 ) { freq . set ( str3 [ ptr2 ] , freq . get ( str3 [ ptr2 ] ) - 1 ) ; ptr2 ++ ; } else { flag = false ; break ; } } } if ( flag && ptr1 == str1 . length && ptr2 == str2 . length ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } let str1 = " " ; let str2 = " " ; let str3 = " " ; convertString ( str1 , str2 , str3 ) ;
Decrypt the String according to given algorithm | JavaScript implementation of the approach ; Function that returns ( num % 26 ) ; Initialize result ; One by one process all digits of ' num ' ; Function to return the decrypted String ; To store the final decrypted answer ; One by one check for each character if it is a numeric character ; Modulo the number found in the String by 26 ; Driver code ; Print the decrypted string
let MOD = 26 ; function modulo_by_26 ( num ) { let res = 0 ; for ( let i = 0 ; i < num . length ; i ++ ) { res = ( ( res * 10 + num [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) % MOD ) ; } return res ; } function decrypt_message ( s ) { let decrypted_str = " " ; let num_found_so_far = " " ; for ( let i = 0 ; i < s . length ; ++ i ) { if ( s [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && s [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) { num_found_so_far += s [ i ] ; } else if ( num_found_so_far . length > 0 ) { decrypted_str += String . fromCharCode ( ' ' . charCodeAt ( 0 ) + modulo_by_26 ( num_found_so_far ) ) ; num_found_so_far = " " ; } } if ( num_found_so_far . length > 0 ) { decrypted_str += String . fromCharCode ( ' ' . charCodeAt ( 0 ) + modulo_by_26 ( num_found_so_far ) ) ; } return decrypted_str ; } let s = " " ; document . write ( decrypt_message ( s ) ) ;
Find the N | Function to calculate nth permutation of string ; Creating an empty stack ; Subtracting 1 from N because the permutations start from 0 in factroid method ; Loop to generate the factroid of the sequence ; Loop to generate nth permutation ; Remove 1 - element in each cycle ; Final answer ; Driver code
function string_permutation ( n , str ) { let s = [ ] ; let result = ' ' ; n = n - 1 ; for ( let i = 1 ; i < str . length + 1 ; i ++ ) { s . push ( n % i ) ; n = Math . floor ( n / i ) ; } let len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { let a = s [ s . length - 1 ] ; result += str [ a ] ; let j ; for ( j = a ; j < str . length ; j ++ ) str = str . substring ( 0 , j ) + str . charAt ( j + 1 ) + str . substring ( j + 1 ) ; str = str . substring ( 0 , j + 1 ) ; s . pop ( ) ; } document . write ( result , ' ' ) ; } let str = " " ; n = 11 ; string_permutation ( n , str ) ;
Defanged Version of Internet Protocol Address | Function to generate a defanged version of IP address . ; Loop to iterate over the characters of the string ; Driven Code
function GeberateDefangIP ( str ) { var defangIP = " " ; str . split ( ' ' ) . forEach ( function ( letter ) { ( letter == ' ' ) ? defangIP += " " : defangIP += letter ; } ) return defangIP ; } var str = " " ; document . write ( GeberateDefangIP ( str ) ) ;
Generate a string with maximum possible alphabets with odd frequencies | Function to generate a string of length n with maximum possible alphabets each occuring odd number of times . ; If n is odd ; Add all characters from b - y ; Append a to fill the remaining length ; If n is even ; Add all characters from b - z ; Append a to fill the remaining length ; Driven code
function generateTheString ( n ) { var ans = " " ; if ( n % 2 ) { for ( var i = 0 ; i < min ( n , 24 ) ; i ++ ) { ans += ( char ) ( ' ' + i ) ; } if ( n > 24 ) { for ( var i = 0 ; i < ( n - 24 ) ; i ++ ) ans += ' ' ; } } else { for ( var i = 0 ; i < Math . min ( n , 25 ) ; i ++ ) { ans += String . fromCharCode ( ' ' . charCodeAt ( 0 ) + i ) ; } if ( n > 25 ) { for ( var i = 0 ; i < ( n - 25 ) ; i ++ ) ans += ' ' ; } } return ans ; } var n = 34 ; document . write ( generateTheString ( n ) ) ;
Move all occurrence of letter ' x ' from the string s to the end using Recursion | Function to move all ' x ' in the end ; Store current character ; Check if current character is not ' x ' ; Recursive function call ; Check if current character is ' x ' ; Driver code
function moveAtEnd ( s , i , l ) { if ( i >= l ) return ; let curr = s [ i ] ; if ( curr != ' ' ) document . write ( curr ) ; moveAtEnd ( s , i + 1 , l ) ; if ( curr == ' ' ) document . write ( curr ) ; return ; } let s = " " ; let l = s . length ; moveAtEnd ( s , 0 , l ) ;
Construct a string of length L such that each substring of length X has exactly Y distinct letters | javascript implementation to construct a string of length L such that each substring of length X has exactly Y distinct letters . ; Initialize p equal to the ASCII value of a ; Iterate till the length of the string ; Driver code
function string ( l , x , y ) { var p = 97 ; for ( var j = 0 ; j < l ; j ++ ) { var ans = String . fromCharCode ( p + ( j % y ) ) ; document . write ( ans ) ; } } var l = 6 ; var x = 5 ; var y = 3 ; string ( l , x , y ) ;
Find the final co | Function to print the final position of the point after traversing through the given directions ; Traversing through the given directions ; If its north or south the point will move left or right ; If its west or east the point will move upwards or downwards ; Returning the final position ; Driver Code
function finalCoordinates ( SX , SY , D ) { for ( let i = 0 ; i < D . length ; i ++ ) { if ( D [ i ] == ' ' ) SY += 1 ; else if ( D [ i ] == ' ' ) SY -= 1 ; else if ( D [ i ] == ' ' ) SX += 1 ; else SX -= 1 ; } let ans = ' ' + ( SX ) . toString ( ) + ' ' + ( SY ) . toString ( ) + ' ' ; document . write ( ans ) ; } let SX = 2 , SY = 2 ; let D = " " ; finalCoordinates ( SX , SY , D . split ( " " ) ) ;
Frequency of smallest character in first sentence less than that of second sentence | JS program for the above approach ; Function to count the frequency of minimum character ; Sort the string s ; Return the count with smallest character ; Function to count number of frequency of smallest character of string arr1 [ ] is less than the string in arr2 [ ] ; To store the frequency of smallest character in each string of arr2 ; Traverse the arr2 [ ] ; Count the frequency of smallest character in string s ; Append the frequency to freq [ ] ; Sort the frequency array ; Traverse the array arr1 [ ] ; Count the frequency of smallest character in string s ; find the element greater than f ; Find the count such that arr1 [ i ] < arr2 [ j ] ; Print the count ; Driver Code ; Function Call
function upper_bound ( freq , f ) { let low = 0 , high = freq . length - 1 ; while ( low < high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( freq [ mid ] > f ) high = mid ; else low = mid + 1 ; } return ( freq [ low ] < f ) ? low ++ : low ; } function countMinFreq ( s ) { s = s . split ( ' ' ) . sort ( ) . join ( ' ' ) ; let x = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == s [ 0 ] ) x += 1 ; } return x ; } function countLessThan ( arr1 , arr2 ) { let freq = [ ] ; for ( let i = 0 ; i < arr2 . length ; i ++ ) { let f = countMinFreq ( arr2 [ i ] ) ; freq . push ( f ) ; } freq = freq . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < arr1 . length ; i ++ ) { let f = countMinFreq ( arr1 [ i ] ) ; let it = upper_bound ( freq , f ) ; let cnt = freq . length - ( it ) ; document . write ( cnt , ' ' ) ; } } let arr1 , arr2 ; arr1 = [ " " , " " ] ; arr2 = [ " " , " " , " " , " " ] ; countLessThan ( arr1 , arr2 ) ;
Lexicographically all Shortest Palindromic Substrings from a given string | Function to find all lexicographically shortest palindromic substring ; Array to keep track of alphabetic characters ; Iterate to prlet all lexicographically shortest substring ; Driver Code
function shortestPalindrome ( s ) { let abcd = Array . from ( { length : 26 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < s . length ; i ++ ) abcd [ s [ i ] . charCodeAt ( ) - 97 ] = 1 ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( abcd [ i ] == 1 ) { document . write ( String . fromCharCode ( i + 97 ) + " " ) ; } } } let s = " " ; shortestPalindrome ( s . split ( ' ' ) ) ;
Remove duplicates from string keeping the order according to last occurrences | Javascript program to remove duplicate character from character array and print in sorted order ; Used as index in the modified String ; Traverse through all characters ; Check if str [ i ] is present before it ; If not present , then add it to result . ; Driver code
function removeDuplicates ( str ) { let n = str . length ; let res = " " ; for ( let i = 0 ; i < n ; i ++ ) { let j ; for ( j = i + 1 ; j < n ; j ++ ) if ( str [ i ] == str [ j ] ) break ; if ( j == n ) res = res + str [ i ] ; } return res ; } let str = " " ; document . write ( removeDuplicates ( str ) ) ;
Remove duplicates from string keeping the order according to last occurrences | Javascript program to remove duplicate character from character array and print in sorted order ; Used as index in the modified string ; Create an empty hash table ; Traverse through all characters from right to left ; If current character is not in ; Reverse the result string ; Driver code
function removeDuplicates ( str ) { var n = str . length ; var s = new Set ( ) ; var res = " " ; for ( var i = n - 1 ; i >= 0 ; i -- ) { if ( ! s . has ( str [ i ] ) ) { res = res + str [ i ] ; s . add ( str [ i ] ) ; } } res = res . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; return res ; } var str = " " ; document . write ( removeDuplicates ( str ) ) ;
Count of numbers in a range that does not contain the digit M and which is divisible by M . | Function to count all the numbers which does not contain the digit ' M ' and is divisible by M ; Storing all the distinct digits of a number ; Checking if the two conditions are satisfied or not ; Lower Range ; Upper Range ; The digit
function contain ( L , U , M ) { let count = 0 ; for ( let j = L ; j < U ; j ++ ) { let num = new Set ( ) ; let str = String ( j ) ; num . add ( str ) ; if ( j % M == 0 && ! num . has ( String ( M ) ) ) { count += 1 ; } } document . write ( count - 2 ) ; } let L = 106 ; let U = 200 ; let M = 7 ; contain ( L , U , M ) ;
Longest string which is prefix string of at least two strings | Javascript program to find longest string which is prefix string of at least two strings ; Function to find Max length of the prefix ; Base case ; Iterating over all the alphabets ; Checking if char exists in current string or not ; If atleast 2 string have that character ; Recursive call to i + 1 ; Initialising strings ; push strings into vectors .
let max1 = 0 ; function MaxLength ( v , i , m ) { if ( i >= m ) { return m - 1 ; } for ( let k = 0 ; k < 26 ; k ++ ) { let c = String . fromCharCode ( ' ' . charCodeAt ( 0 ) + k ) ; let v1 = [ ] ; for ( let j = 0 ; j < v . length ; j ++ ) { if ( v [ j ] [ i ] == c ) { v1 . push ( v [ j ] ) ; } } if ( v1 . length >= 2 ) { max1 = Math . max ( max1 , MaxLength ( v1 , i + 1 , m ) ) ; } else { max1 = Math . max ( max1 , i - 1 ) ; } } return max1 ; } let s1 , s2 , s3 , s4 , s5 ; s1 = " " ; s2 = " " ; s3 = " " ; s4 = " " ; s5 = " " ; let v = [ ] ; v . push ( s1 ) ; v . push ( s2 ) ; v . push ( s3 ) ; v . push ( s4 ) ; v . push ( s5 ) ; let m = v [ 0 ] . length ; document . write ( MaxLength ( v , 0 , m ) + 1 + " " ) ;
Periodic Binary String With Minimum Period and a Given Binary String as Subsequence . | Function to find the periodic string with minimum period ; Print the string S if it consists of similar elements ; Find the required periodic string with period 2 ; Driver Code
function findPeriodicString ( S ) { let l = 2 * S . length ; let count = 0 ; for ( let i = 0 ; i < S . length ; i ++ ) { if ( S [ i ] == ' ' ) count ++ ; } if ( count == S . length count == 0 ) document . write ( S + " " ) ; else { let arr = new Array ( l ) ; for ( let i = 0 ; i < l ; i += 2 ) { arr [ i ] = ' ' ; arr [ i + 1 ] = ' ' ; } for ( let i = 0 ; i < l ; i ++ ) document . write ( arr [ i ] ) ; document . write ( " " ) ; } } let S = " " ; findPeriodicString ( S ) ;
Count the minimum number of groups formed in a string | Function to count the minimum number of groups formed in the given string s ; Initializing count as one since the string is not NULL ; Comparing adjacent characters ; Driver code
function group_formed ( S ) { let count = 1 ; for ( let i = 0 ; i < S . length - 1 ; i ++ ) { if ( S [ i ] != S [ i + 1 ] ) count += 1 ; } document . write ( count ) ; } let S = " " ; group_formed ( S ) ;
Find the Substring with maximum product | Function to return the value of a character ; Function to find the maximum product subString ; To store subStrings ; Check if current product is maximum possible or not ; If product is 0 ; Return the subString with maximum product ; Driver Code ; Function call
function value ( x ) { return ( x . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; } function maximumProduct ( str , n ) { let answer = " " , curr = " " ; let maxProduct = 0 , product = 1 ; for ( let i = 0 ; i < n ; i ++ ) { product *= ( 1 * value ( str [ i ] ) ) ; curr += str [ i ] ; if ( product >= maxProduct ) { maxProduct = product ; answer = curr ; } if ( product == 0 ) { product = 1 ; curr = " " ; } } return answer ; } let str = " " ; let n = str . length ; document . write ( maximumProduct ( str , n ) + " " ) ;
Sum of minimum and the maximum difference between two given Strings | Function to find the sum of the minimum and the maximum difference between two given strings ; Variables to store the minimum difference and the maximum difference ; Iterate through the length of the string as both the given strings are of the same length ; For the maximum difference , we can replace " + " in both the strings with different char ; For the minimum difference , we can replace " + " in both the strings with the same char ; Driver code
function solve ( a , b ) { var l = a . length ; var min = 0 , max = 0 ; for ( var i = 0 ; i < l ; i ++ ) { if ( a [ i ] == ' ' b [ i ] == ' ' a [ i ] != b [ i ] ) max ++ ; if ( a [ i ] != ' ' && b [ i ] != ' ' && a [ i ] != b [ i ] ) min ++ ; } document . write ( min + max ) ; } var s1 = " " , s2 = " " ; solve ( s1 , s2 ) ;
Minimum letters to be removed to make all occurrences of a given letter continuous | Function to find the minimum number of deletions required to make the occurrences of the given character K continuous ; Find the first occurrence of the given letter ; Iterate from the first occurrence till the end of the sequence ; Find the index from where the occurrence of the character is not continuous ; Update the answer with the number of elements between non - consecutive occurrences of the given letter ; Update the count for all letters which are not equal to the given letter ; Return the count ; Driver code ; Calling the function ; Calling the function
function noOfDeletions ( str , k ) { var ans = 0 , cnt = 0 , pos = 0 ; while ( pos < str . length && str [ pos ] != k ) { pos ++ ; } var i = pos ; while ( i < str . length ) { while ( i < str . length && str [ i ] == k ) { i = i + 1 ; } ans = ans + cnt ; cnt = 0 ; while ( i < str . length && str [ i ] != k ) { i = i + 1 ; cnt = cnt + 1 ; } } return ans ; } var str1 = " " ; var k1 = ' ' ; document . write ( noOfDeletions ( str1 , k1 ) + " " ) ; var str2 = " " ; var k2 = ' ' ; document . write ( noOfDeletions ( str2 , k2 ) ) ;
Check whether an array of strings can correspond to a particular number X | Function to find the maximum base possible for the number N ; Function to find the decimal equivalent of the number ; Condition to check if the number is convertible to another base ; Function to check that the array can correspond to a number X ; counter to count the numbers those are convertible to X ; Loop to iterate over the array ; Convert the current String to every base for checking whether it will correspond to X from any base ; Condition to check if every number of the array can be converted to X ; Driver Code ; The set of Strings in base from [ 2 , 36 ]
function val ( c ) { if ( c >= ' ' && c <= ' ' ) return c - ' ' ; else return c - ' ' + 10 ; } function toDeci ( str , base ) { let len = str . length ; let power = 1 ; let num = 0 ; let i ; for ( i = len - 1 ; i >= 0 ; i -- ) { if ( val ( str [ i ] ) >= base ) { return - 1 ; } num += val ( str [ i ] ) * power ; power = power * base ; } return num ; } function checkCorrespond ( str , x ) { let counter = 0 ; let n = str . length ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 2 ; j <= 36 ; j ++ ) { if ( toDeci ( str [ i ] , j ) == x ) { counter ++ ; break ; } } } if ( counter == n ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } let x = 16 ; let str = [ " " , " " , " " ] ; checkCorrespond ( str , x ) ;
Count of same length Strings that exists lexicographically in between two given Strings | Function to find the count of strings less than given string lexicographically ; Find length of string s ; Looping over the string characters and finding strings less than that character ; Function to find the count of same length Strings that exists lexicographically in between two given Strings ; Count string less than S1 ; Count string less than S2 ; Total strings between S1 and S2 would be difference between the counts - 1 ; If S1 is lexicographically greater than S2 then return 0 , otherwise return the value of totalString ; Driver code
function LexicoLesserStrings ( s ) { var count = 0 ; var len ; len = s . length ; for ( var i = 0 ; i < len ; i ++ ) { count += ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) * Math . pow ( 26 , len - i - 1 ) ; } return count ; } function countString ( S1 , S2 ) { var countS1 , countS2 , totalString ; countS1 = LexicoLesserStrings ( S1 ) ; countS2 = LexicoLesserStrings ( S2 ) ; totalString = countS2 - countS1 - 1 ; return totalString < 0 ? 0 : totalString ; } var S1 , S2 ; S1 = " " ; S2 = " " ; document . write ( countString ( S1 , S2 ) ) ;
Longest Subsequence of a String containing only vowels | Function to check whether a character is vowel or not ; Returns true if x is vowel ; Function to find the longest subsequence which contain all vowels ; Length of the string ; Iterating through the string ; Checking if the character is a vowel or not ; If it is a vowel , then add it to the final string ; Driver code
function isVowel ( x ) { x = ( x . toLowerCase ( ) ) ; return ( x == ' ' x == ' ' x == ' ' x == ' ' x == ' ' ) ; } function longestVowelSubsequence ( str ) { var answer = " " ; var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) { if ( isVowel ( str [ i ] ) ) { answer += str [ i ] ; } } return answer ; } var str = " " ; document . write ( longestVowelSubsequence ( str ) ) ;
Maximum repeated frequency of characters in a given string | Function to find the maximum repeated frequency of the characters in the given string ; Hash - Array to store the frequency of characters ; Loop to find the frequency of the characters ; Hash map to store the occurrence of frequencies of characters ; Loop to find the maximum Repeated frequency from hash - map ; Driver Code ; Function Call
function findMaxFrequency ( s ) { var arr = Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < s . length ; i ++ ) arr [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; var hash = new Map ( ) ; for ( var i = 0 ; i < 26 ; i ++ ) if ( arr [ i ] != 0 ) { if ( hash . has ( arr [ i ] ) ) hash . set ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) else hash . set ( arr [ i ] , 1 ) } var max_count = 0 , res = - 1 ; hash . forEach ( ( value , key ) => { if ( max_count < value ) { res = key ; max_count = value ; } } ) ; document . write ( " " + res + " " + max_count + " " ) ; } var s = " " ; findMaxFrequency ( s ) ;
XOR of two Binary Strings | Function to find the XOR of the two Binary Strings ; Loop to iterate over the Binary Strings ; If the Character matches ; Driver Code
function xoring ( a , b , n ) { let ans = " " ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == b [ i ] ) ans += " " ; else ans += " " ; } return ans ; } let a = " " ; let b = " " ; let n = a . length ; let c = xoring ( a , b , n ) ; document . write ( c ) ;
Find Kth largest string from the permutations of the string with two characters | Function to print the kth largest string ; loop to iterate through series ; total takes the position of second y ; i takes the position of first y ; calculating first y position ; calculating second y position from first y ; print all x before first y ; print first y ; print all x between first y and second y ; print second y ; print x which occur after second y ; Driver code
function kthString ( n , k ) { var total = 0 ; var i = 1 ; while ( total < k ) { total = total + n - i ; i ++ ; } var first_y_position = i - 1 ; var second_y_position = k - ( total - n + first_y_position ) ; for ( var j = 1 ; j < first_y_position ; j ++ ) document . write ( " " ) ; document . write ( " " ) ; var j = first_y_position + 1 ; while ( second_y_position > 1 ) { document . write ( " " ) ; second_y_position -- ; j ++ ; } document . write ( " " ) ; while ( j < n ) { document . write ( " " ) ; j ++ ; } } var n = 5 ; var k = 7 ; kthString ( n , k ) ;
Largest and Smallest N | Function to return the largest N - digit number in Octal Number System ; Append '7' N times ; Function to return the smallest N - digit number in Octal Number System ; Append '0' ( N - 1 ) times to 1 ; Function to print the largest and smallest N - digit Octal number ; Driver code ; Function Call
function findLargest ( N ) { var largest = new Array ( N + 1 ) . join ( ' ' ) ; return largest ; } function findSmallest ( N ) { var smallest = " " + new Array ( N ) . join ( ' ' ) ; return smallest ; } function printLargestSmallest ( N ) { document . write ( " " + findLargest ( N ) + " " ) ; document . write ( " " + findSmallest ( N ) ) ; } var N = 4 ; printLargestSmallest ( N ) ;