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.
clever solution!
Got it! Thanks for the clarification.
It doesn't says both are valid, it says one digit can belong to two adjacent digit-pairs.
For that string your code should return false, as the similar sample test shows.
Note: a digit can belong to two adjacent digit-pairs. For example, in string 1???9??1, 1???9 is a digit-pair, 9??1 is also a digit-pair.
Could someone explain this to me.
How does the above represent two valid digit-pairs?
Or is it a typo?
Because there are 3 ??? between the 1 and 9
However there is not three ??? which follow the 9.
So how can the answer be valid?
Also looking at the sample tests shows
Test.assertEquals(sum10("1???x9??1"), false)
That is what I would expect.
So is the description meant to read:
"***Note: a digit can belong to two adjacent digit-pairs.
For example, in string 1???9???1, 1???9 is a digit-pair, 9???1 is also a digit-pair."
Thank you
Aha! I understand now. Thank you
I solved the kata in JavaScript, so I am able to see your code. Your code passes the first sample tests, but fails in some of the series
for example
I don't think it works fine in VSC either.
Thank you, akar-0
But as you can see I posted exactly the input so that you can
see what I am using!
All I did was change the 'test.assert...' string to 'console.log'
That's it!
And ran both programs which displayed the answers straightaway
As you can see
I would gladly send you the source code of my solution so that you can see what I mean, if that helps!
This means you are using too much memory (you are probably building a gigantic array or something like this, or a part of your code keeps pushing value into something and never stops), and it is not a kata issue.
Advice: your
while
loop is probably the culprit. You are probably not testing your code with the same input in VSC as here. Please refer to the documentation: https://docs.codewars.com/training/troubleshooting/Greetings
I have written two different solutions which both use a loop. No recursion.
Both run fine in Visual Studio but both crash with memory problems in Codewars
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
I have tried both 'resetting' and changing the Node versions.
I get the same errors
How do I proceed?
This is my output from Visual Code:
console.log(splitWithoutLoss("hello world!", " |"), ["hello ", "world!"]);
console.log(splitWithoutLoss("hello world!", "o|rl"), ["hello wo", "rld!"]);
console.log(splitWithoutLoss("hello world!", "ello| "), ["hello", " world!"]);
console.log(splitWithoutLoss("hello world!", "hello wo|rld!"), [
"hello wo",
"rld!",
]);
console.log(splitWithoutLoss("hello world!", "h|ello world!"), [
"h",
"ello world!",
]);
console.log(splitWithoutLoss("hello world! hello world!", " |"), [
"hello ",
"world! ",
"hello ",
"world!",
]);
console.log(splitWithoutLoss("hello world! hello world!", "o|rl"), [
"hello wo",
"rld! hello wo",
"rld!",
]);
console.log(splitWithoutLoss("hello world! hello world!", "ello| "), [
"hello",
" world! hello",
" world!",
]);
console.log(splitWithoutLoss("hello world! hello world!", "hello wo|rld!"), [
"hello wo",
"rld! hello wo",
"rld!",
]);
console.log(splitWithoutLoss("hello hello hello", " | "), [
"hello ",
" hello ",
" hello",
]);
Which Produced:
[ 'hello ', 'world!' ] [ 'hello ', 'world!' ]
[ 'hello wo', 'rld!' ] [ 'hello wo', 'rld!' ]
[ 'hello', ' world!' ] [ 'hello', ' world!' ]
[ 'hello wo', 'rld!' ] [ 'hello wo', 'rld!' ]
[ 'h', 'ello world!' ] [ 'h', 'ello world!' ]
[ 'hello ', 'world! ', 'hello ', 'world!' ] [ 'hello ', 'world! ', 'hello ', 'world!' ]
[ 'hello wo', 'rld! hello wo', 'rld!' ] [ 'hello wo', 'rld! hello wo', 'rld!' ]
[ 'hello', ' world! hello', ' world!' ] [ 'hello', ' world! hello', ' world!' ]
[ 'hello wo', 'rld! hello wo', 'rld!' ] [ 'hello wo', 'rld! hello wo', 'rld!' ]
[ 'hello ', ' hello ', ' hello' ] [ 'hello ', ' hello ', ' hello' ]
This comment is hidden because it contains spoiler information about the solution
Bitwise NOTing any number x yields -(x + 1).
Good job!
I also think about using RegExp and match(), but I not so good in it.