May 16 Codewars
WOW the things you don't know until you ask! I have only been pushing the codewars I get right and I haven't been pushing the ones I don't get! GRRRR I should know better that you learn from your mistakes more than from what you already know. I will now be posting the codewars that I did not get right as well. It's fine it's ok, oh well now I know!
This is the one I got correct. Problem: Return all positive integers as negative, any negatives and 0 should be left as is.
function makeNegative(num) {
if (num < 0){
return num
} else {
return -num
}
}
The one I got wrong was a tough one for me.
Problem: Replace all words in string with the word 'sex'
My attempt:
function toFreud(string) {
return string.replace(' ','sex');
}
Actual solution:
function toFreud(string) {
return string.replace(/\S+/g, 'sex');
}
I still have yet to fully understand the (/\S+/g) and when and how to use it.