diff options
Diffstat (limited to 'challenge-278/zapwai/javascript/ch-2.js')
| -rw-r--r-- | challenge-278/zapwai/javascript/ch-2.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-278/zapwai/javascript/ch-2.js b/challenge-278/zapwai/javascript/ch-2.js new file mode 100644 index 0000000000..1753075d96 --- /dev/null +++ b/challenge-278/zapwai/javascript/ch-2.js @@ -0,0 +1,24 @@ +let str = "challenge"; +let mychar = "e"; +proc(str, mychar); +str = "programming"; +mychar = "a"; +proc(str, mychar); +str = "champion"; +mychar = "b"; +proc(str, mychar); +function proc(str, mychar) { + console.log("Input: str =", str, "mychar =", mychar); + let ind = str.indexOf(mychar); + if (ind == -1) { + console.log("Output:",str); + } else { + let begin = str.substr(0, ind + 1); + let endy = str.substr(ind + 1); + console.log(arrange(begin)+endy); + } +} +function arrange(word) { + let arr = word.split(""); + return arr.sort().join(separator=''); +} |
