+ 2

is var hypeup function when it run why (adore(x)) runs first

confused with output become input function in var hypeup function complexity and why just calling function doesnt give any output plz fixed the result as 'Js rocks, y'all!' var ender = (input) => (ending) => input + ending; var adore = ender("rocks"); var announce = ender(",y'll"); var exclaim = ender("!"); var hypeup = (x) => exclaim(announce(adore(x))); hypeup("Js")

8th Jan 2019, 3:10 AM
Danielov
Danielov - avatar
3 Answers
+ 2
9th Jan 2019, 12:37 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 3
if there is not space in ender('rocks') it split every single char if i put space ender(' rocks ') it split in words.
9th Jan 2019, 12:16 PM
Danielov
Danielov - avatar
+ 2
The adore(x) is nested therefore executed first. There will be no output generated if you did not declare it to do so to an alert, DOM, consolelog, etc. Without it, the code still be executed. For example you can monitor/execute/debug an function inside: console.log(hypeup()); // or alert(typeof hypeup()); To solve your required output, it can be done in many ways from this point. Re-assamble your code so the output will be correct for example. But if you want the code to be the same you can: - split() the string at the whitespace to be converted as an array which can be reversed. This will result that each word will be an array element. - reverse() the array. - join() the array back together to be converted back to a string. Have a look at the changes, hope it helps👍 https://code.sololearn.com/WV3r3RdOzZG8/?ref=app
8th Jan 2019, 4:53 AM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar