DEV Community

Discussion on: Getting started with MojiScript: FizzBuzz (part 1)

Collapse
 
jorge_rockr profile image
Jorge Ramón

Amazing!

Just one question, does it has a better performance than normal JavaScript for Node.js?

Or it is just for doing functional coding style?

Collapse
 
joelnet profile image
JavaScript Joel • Edited

Thanks, but you are asking the wrong question!

It functions better than JavaScript.

Look at this JavaScript code. It is complicated to understand the output. This code outputs all give 6's after 1 second.

for (var i = 1; i < 6; i++) {
  setTimeout(() => console.log(i), 1000)
}
// => 6
// => 6
// => 6
// => 6
// => 6

Now look at the MojiScript alternative. This program will output 1 through 5 with 1 second delay between each output. (imports have been excluded for brevity)

const sleepThenLog = pipe ([
  sleep (1000),
  log
])

const main = pipe ([
  ({ start, end }) => range (start) (end),
  map (sleepThenLog)
])

main ({ start: 1, end: 6 })
// => 1
// => 2
// => 3
// => 4
// => 5

Did you notice that? Did we just create an asynchronous map? Shhh. articles coming out on Asynchronous map, filter, and reduce shortly. Stay tuned!