0

3. Write a JavaScript function that generates all combinations of a string.

11th Dec 2016, 9:20 PM
Nashwan Aziz
Nashwan Aziz - avatar
11 Réponses
+ 3
this question is really hard. i did it once using recursion. and considering all letters in string are different.
12th Dec 2016, 6:59 AM
manish rawat
manish rawat - avatar
+ 2
function combinator (s) { list_of_strings = new Array(); for(i=0;i<s.length;i++) { for(j=i+1;j<s.length+1;j++) { list_of_strings.push(s.slice(i, j)); } } return list_of_strings; } document.write(combinator("dog"));
12th Dec 2016, 7:28 PM
Rishi Anand
Rishi Anand - avatar
+ 1
please answer
12th Dec 2016, 6:49 PM
Nashwan Aziz
Nashwan Aziz - avatar
+ 1
to java script
12th Dec 2016, 6:49 PM
Nashwan Aziz
Nashwan Aziz - avatar
+ 1
You'll have to change the last line to make it suitable
12th Dec 2016, 7:28 PM
Rishi Anand
Rishi Anand - avatar
+ 1
thank you
12th Dec 2016, 7:43 PM
Nashwan Aziz
Nashwan Aziz - avatar
+ 1
my pleasure
12th Dec 2016, 7:47 PM
Rishi Anand
Rishi Anand - avatar
+ 1
Write a JavaScript function that returns a .4 passed string with letters in alphabetical 'order. Example string : 'webmaster 'Expected Output : 'abeemrstw Assume punctuation and numbers symbols .are not included in the passed string
12th Dec 2016, 10:49 PM
Nashwan Aziz
Nashwan Aziz - avatar
+ 1
3. Write a JavaScript function that generates all combinations of a string. function combinator (s) { list_of_strings = new Array(); for(i=0;i<s.length;i++) { for(j=i+1;j<s.length+1;j++) { list_of_strings.push(s.slice(i, j)); } } return list_of_strings; } document.write(combinator("dog"));
13th Dec 2016, 1:44 PM
Nashwan Aziz
Nashwan Aziz - avatar
0
Hello guys! I've got a new simple solution using built-in functions
26th Jun 2019, 4:15 PM
Ahadi Habib Josue
Ahadi Habib Josue - avatar
0
function combine(str){ const result = []; for(let i = 1; i < Math.pow(2, str.length) - 1; i++) result.push([...str].filter((_, pos) => (i >> pos) & 1).join("")); return result; } console.log(combine("dog"));
26th Jun 2019, 4:15 PM
Ahadi Habib Josue
Ahadi Habib Josue - avatar