Added string subsequence in JS (#196)

* Added string subsequence in js

* remove extra line
pull/208/head
Toihir Halim 2021-04-15 17:23:25 +02:00 committed by GitHub
parent ee31aca70b
commit 0474e3e216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View File

@ -18,6 +18,7 @@
### JavaScript
1. [Palindrome Check](js/palindrome.js)
2. [All subsequences](js/sequence.js)
### Java

View File

@ -0,0 +1,44 @@
var list = [];
const subsequence = (input, output = '') => {
if (input === "") {
if (output !== '' && !list.includes(output)) list.push(output);
return;
}
subsequence(input.substr(1), output + input.charAt(0));
subsequence(input.substr(1), output);
}
subsequence('abc');
console.log('abc', list);
list = [];
subsequence('aaa');
console.log('aaa', list);
list = [];
subsequence('hello');
console.log('hello', list);
/*
to run the file:
Node sequence.js
result
abc [
'abc', 'ab',
'ac', 'a',
'bc', 'b',
'c'
]
aaa [ 'aaa', 'aa', 'a' ]
hello [
'hello', 'hell', 'helo', 'hel',
'heo', 'he', 'hllo', 'hll',
'hlo', 'hl', 'ho', 'h',
'ello', 'ell', 'elo', 'el',
'eo', 'e', 'llo', 'll',
'lo', 'l', 'o'
]
*/