JavaScript function that generates all combinations of a string.
function combu(s){
var buff = [];
var res = [];
for (i=0;i<s.length;i++){
buff = [s[i]];
var index=0;
while(res[index]){
buff.push(''+res[index]+s[i]);
index++;
}
res = res.concat(buff);
}
return res;
}
combu('abc'); function combString(str){
var lenStr = str.length;
var result = [];
var indexCurrent = 0;
while(indexCurrent < lenStr){
var char = str.charAt(indexCurrent);
var x;
var arrTemp = [char];
for(x in result) {
arrTemp.push(""+result[x]+char);
}
result = result.concat(arrTemp);
indexCurrent++;
}
return result;
}
console.log(combString("abc"));
Also in JavaScript:
- javascript test login password in bootstrap studio
- sort array based on another array
- format JSON code javascript
- javascript document load
- jquery add class
- multiple case switch javascript
- Modify the function increment by adding default parameters so that it will add 1 to number if value is not specified.
- javascript loop through arrya
- javascript map function
- javascript base64 decode
- react bootstrap hide toggle menu when scrolling down
- javascript filter and order
- sleeping in js
- mdn select event
- how to create array in javascript
- Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied
- react native AsyncStorage
- Returning Boolean Values from Functions
- jquery loop through each child element
- span change jquery
- jquery click event
- javascript array filter
- jquery clear file input
- math js