If you notice, the code actually splits the chars into an array prior to do any permutation, so you simply remove the join and split operation
var permArr = [], usedChars = []; function permute(input) { var i, ch; for (i = 0; i < input.length; i++) { ch = input.splice(i, 1)[0]; usedChars.push(ch); if (input.length == 0) { permArr.push(usedChars.slice()); } permute(input); input.splice(i, 0, ch); usedChars.pop(); } return permArr }; document.write(JSON.stringify(permute([5, 3, 7, 1])));
Related Posts:
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
- How can I check for “undefined” in JavaScript?
- How to make history.back() without getting a warning on the browser to reload the page?
- Split string into array
- convert Hsl to rgb and hex
- How to play audio?
- What does jQuery.fn mean?
- “Uncaught TypeError: Cannot read property ‘style’ of null at.. “
- Difference between document.referrer and window.parent.location.href
- JavaScript replace/regex
- how to render a react component using ReactDOM Render
- What does “javascript:void(0)” mean?
- What does this symbol mean in JavaScript?
- What is the difference between state and props in React?
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
- OnChange event using React JS for drop down
- how to get the last character of a string?
- Set timeout for ajax (jQuery)
- Escaping Discord subset of markdown
- ESLint Parsing error: Unexpected token
- Angular ForEach in Angular4/Typescript?
- Timers in React Native (this.setTimeout)
- How to handle ETIMEDOUT error?
- bootstrap-datetimepicker for bootstrap 4
- Proper way to wait for one function to finish before continuing?
- XMLHttpRequest module not defined/found
- How do you put an image file in a json object?
- How can I add a class to a DOM element in JavaScript?
- Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode
- Module not found: Error: Can’t resolve ‘fs’ in
- TypeError: $(…).modal is not a function with bootstrap Modal
- How to do fade-in and fade-out with JavaScript and CSS
- I want to remove double quotes from a String
- Calculating median – javascript
- Vue is not defined
- How to remove all listeners in an element?
- How do I check if an object has a key in JavaScript?
- npm WARN enoent ENOENT: no such file or directory, open ‘C:\Users\Nuwanst\package.json’
- How to change value of object which is inside an array using JavaScript or jQuery?
- How to detect pressing Enter on keyboard using jQuery?
- How to make your Discord Bot always active
- How to write inside a DIV box with javascript
- use Lodash to sort array of object by value
- Chrome/jQuery Uncaught RangeError: Maximum call stack size exceeded
- How to make an HTML back link?
- How to fix getImageData() error The canvas has been tainted by cross-origin data?
- How to make fadeOut effect with pure JavaScript
- How to get unique values in an array
- How to fix Error: listen EADDRINUSE while using NodeJS?
- What is ‘xmlhttp.setRequestHeader();’ and in which situations is it used?
- Write / add data in JSON file using Node.js
- Set scroll position
- .filter is not a function
- Function overloading in Javascript – Best practices
- Wait until flag=true
- momentJS date string add 5 days
- When is a CDATA section necessary within a script tag?
- How to get scrollbar position with Javascript?
- where is create-react-app webpack config and files?
- What does wp-embed.min.js do in WordPress 4.4?
- Gutenberg extend blocks add new class name
- How do I add custom attributes to javascript tags in WordPress?
- How to wrap the content of the main tinyMCE editor with extra tags
- Rest API authentication issue when called from fetch request in bundle.js
- Javascript not working?
- Add Item to Custom TinyMCE Menu
- Listbox return wrong value in WordPress 3.9
- Logout user and delete cookies from the client side?
- wp_enqueue_script & constants?
- How do developers add “Smooth Transitions” to their sites?
- Resolving Javascript errors likely related to Gantry framework
- How can I get my Calculate Contact Form 7 field to update with jQuery? [closed]
- I am trying to add current logged in user to my zoho chat
- Where to upload JavaScript file in WordPress
- Calling a WordPress Custom JavaScript file
- Conditional save return on Gutenberg Block
- Can I alter the block editor’s paste text behavior?
- Custom Block – save.js function not saving attributes
- Headless wp with react. How to handle routes?
- Issues trying to get an element by id
- How do I know if I should enqueue JS code or just include it in ONE PHP function?
- How do I use this javascript correct with wordpress?
- How can I integrate yepnope.js with WordPress (and plugins)?
- How to set javascript options for select2 in PHP array of plugin
- Multiple jQuery inputs or binds in Customizer Control Javascripts
- How to display different content on the same page using different URLS
- Change background video when scrolling reaches a certain ID
- Immediate (e.g. without DOMContentLoaded) JS not working
- Client side pre-save Javascript hook on all admin pages
- Dynamically changing logo on scroll function [closed]
- Script not working in post content
- How to identify which javascript is being executed
- Remove WordPress default registration client side validation?
- How could I add load more posts to my theme? [closed]
- How to keep close a sub-menu under homepage? [closed]
- How to implement custom URL handler to access JS modal content? [closed]
- Javascript button to call custom fields data
- Javascript 2 elements dependent onclick .toggle [closed]