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.
nice
https://regexr.com/ is a great site for trying out and learning regex.
Check it out.
the
c = c > 9
is settingc
equal totrue
if there is digit carried. Thetrue
value is coerced to1
in the next iteration (thec += ...
part).**
is the exponentiation operator. It is part of the ES7 proposal. Documentation here.Explanation: of (/,\s([^,]+)$/)
, -> Find a comma...
\s -> with zero spaces...
([^,]+) -> and one or more non-comma characters at the
$ -> ...end of the string
This comment is hidden because it contains spoiler information about the solution
A cool thing about '~~' is that it will parse a null value or empty string as 0. Very useful here, since the strings can be different lengths.
'~' is a bit operation which inverts bits in number. Bitwise operations works with the integer part of number. So if we use '~~' (double inverting) we get our number in integer representation. In this solution its just rounding number for exclusion zeros before number ('00123' -> '123'). 'c>9' returns true when c>9, true+1 = 2. It's for balance when added.
C = C > 9
probably it's something like carry flag. There are column addition like as4 +
4
8`
you get just 8 and addition is over, but if you add
5 +
5
10
You add
5 + 5
and get10
, but you can write only one digit, the0
. You have to write1
too.But cycle is over because
A
andB
arrays already empty. And result will be0
.In this case you need check if you have reminder from adding.
C = C > 9
just check if number more 9. I.eC = 5 + 5
,C = 10
, and thenC = 10 > 9
,C = true
.In this case a script have to run more one cycle.
And
C
now isBoolean
,true
orfalse
thenC = C + (~~A.pop() + ~~B.pop());
considering asC = 1 + (number + number)
orC = 0 + (number + number)
I.e
true + 1 == 2
ortrue + 0 == 1
Oh it's little difficult even for me. But I hope you can understand basic idea.
~~ it's using for convert any value to integer. For example:
~~undefined = 0
,~~1.1 = 1
,~~"test" = 0
and even~~null = 0
etc.It's good hack if you don't want write various conditions such as
if (a != null || a != undefined)
you just writec = ~~a
and if variable is incorrect,it's just return 0 in any case without any exception.
This comment is hidden because it contains spoiler information about the solution
I've learned it from a combination of things, but I usually use the mozilla developer documents for reference. Hope this helps! https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace.
This comment is hidden because it contains spoiler information about the solution