Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
🙏🙏🙏
Here is the explain to everyone about the
function plus(n) { return function (a) { return a + n } }
Let's say we need to do something like two(plus(three()))
I.The javascript is running from the inside 1st right?
then it will try to calculate three() meaning 3 , there is nothing hard here
II.now to the plus(three())
if u trying to console.log(plus(three())), u will see it return
and nothing is calculated.
or i can say
III. Remember two(something_in_here) function? it
or i can say
To summarize all from 1-> 3, we have everything explained below
==> this mean 2 has been assigned to a!
So that' how.
Use spoiler flag next time please.
This comment is hidden because it contains spoiler information about the solution
wouldnt this return floating point numbers on division and fail the test, or am i missing something?
Note that this code would not work in a strict mode environment. This is not considered a best practice.
Otherwise, clever idea
Use of
this
is a little creepy, but could be mapped to an exported object in a real module.awesome...
Hi @mrkishi,
yes, i meant functions as global 'entities' which can be accessed from the window. I do realise all the katas are in a specific enviroment designed for training purposes only, they're meant to use the global scope, however afaik it's not advisable to implement such a behaviour in a real app, since these functions may interfere with functions from other scripts and libraries.
Hey, @AncientGeek.
There are no global variables in this solution (apart from the functions). The only symbols added to the global scope are the functions
plus
,minus
,times
,dividedBy
, andzero
throughtnine
. These are required to exist in order to pass the kata. :)please correct me if i'm wrong, but isn't it a very bad practice to create variables in the global scope? I wouldn't call it 'clever' per se, but true it is the shortest solution, in this limited 'test' enviroment.
Probably the shortest solution ;)