Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

permutation and combination program in javascript

<script>
// Javascript program to print all permutations of a
// given string.
  
function permute(str, l, r)
{
    if (l == r)
            document.write(str+"<br>");
        else
        {
            for (let i = l; i <= r; i++)
            {
                str = swap(str, l, i);
                permute(str, l + 1, r);
                str = swap(str, l, i);
            }
        }
}
  
function swap(a, i, j)
{
    let temp;
let charArray = a.split("");
temp = charArray[i] ;
charArray[i] = charArray[j];
charArray[j] = temp;
return (charArray).join("");
}
  
let str = "ABC";
let n = str.length;
permute(str, 0, n-1);
  
// This code is contributed by avanitrachhadiya2155
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: js exclude from object 
Javascript :: how to write query string js 
Javascript :: javascript inheritence 
Javascript :: check for palindromes 
Javascript :: input set variable angular 
Javascript :: js get children 
Javascript :: mongoose await save 
Javascript :: How to get previous url in nextjs 
Javascript :: Check if instance is array 
Javascript :: stop python script nodejs 
Javascript :: range number in js 
Javascript :: react-native make android apk 
Javascript :: generate qr code react 
Javascript :: an arrow function 
Javascript :: js do while loop 
Javascript :: simple user agent parse js 
Javascript :: input show validation message 
Javascript :: javascript compare number 
Javascript :: flat function javascript 
Javascript :: aos animation 
Javascript :: gif as animation react 
Javascript :: javascript dynamic variable name 
Javascript :: react multiple classnames 
Javascript :: URLSearchParams 
Javascript :: Run Express in Production Mode 
Javascript :: array.contains javascript 
Javascript :: js range similar to python 
Javascript :: datatable dropdown toggle not working 
Javascript :: console.table in javascript 
Javascript :: React - How to export a pure stateless component 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =