These are chat archives for Codewars/codewars.com/kata-solving-help

1st
Apr 2017
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 04:23
Could I get some quick help with a couple basic katas?
Anika Erceg
@AnikaErceg
Apr 01 2017 06:32
Not sure I can help but, post the kata you are solving and your code here.
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:09
Descending Order:
function descendingOrder(n){
  var splt = n.toString().split('');
  var sec = splt.sort();
  var result = sec.reverse();
  var final = result.join('');
  console.log(final);

}
Anika Erceg
@AnikaErceg
Apr 01 2017 07:10
And when you run that code, what do you get?
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:11
All six incorrect.
Even though I am getting the required results...
Anika Erceg
@AnikaErceg
Apr 01 2017 07:12
What's the kata about precisely?
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:12

Your task is to make a function that can take any non-negative integer as a argument and return it with it's digits in descending order. Essentially, rearrange the digits to create the highest possible number.

Examples:

Input: 21445 Output: 54421

Input: 145263 Output: 654321

Input: 1254859723 Output: 9875543221

Anika Erceg
@AnikaErceg
Apr 01 2017 07:14
And you can't tell me what your output is?
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:15
Lol one sec
Donald Sebastian Leung
@DonaldKellett
Apr 01 2017 07:15
@PhillipSchmidt__twitter may you please provide the link to that Kata?
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:15
Test Results:
Log
0
✘ Expected: 0, instead got: undefined
Log
1
✘ Expected: 1, instead got: undefined
Log
111
✘ Expected: 111, instead got: undefined
Log
51
✘ Expected: 51, instead got: undefined
Log
2110
✘ Expected: 2110, instead got: undefined
Log
987654321
✘ Expected: 987654321, instead got: undefined
Donald Sebastian Leung
@DonaldKellett
Apr 01 2017 07:16
Ah, I see :wink: You've forgotten your return statement :wink:
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:16
Oh alright one sec
Anika Erceg
@AnikaErceg
Apr 01 2017 07:17
Hah, I didn't even notice that :D
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:17
Well it still didnt work. Unless I am doing it wrong.
Which could be lol
'''
Anika Erceg
@AnikaErceg
Apr 01 2017 07:18
What did you get now?
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:18
return final; right? Or no semi?
Donald Sebastian Leung
@DonaldKellett
Apr 01 2017 07:18
Another thing that I've noticed is that one of your variables is named "final" which may or may not be a reserved keyword in JavaScript.
Maybe try renaming it?
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:18
Ill try it.
Anika Erceg
@AnikaErceg
Apr 01 2017 07:18
Also, perhaps you want to turn your strings back into integers
Donald Sebastian Leung
@DonaldKellett
Apr 01 2017 07:19
@AnikaErceg True that, but I think Test.assertEquals in JavaScript uses loose comparison == such that "1" == 1 so I think it shouldn't matter
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:20
Changed final to last
no change
Donald Sebastian Leung
@DonaldKellett
Apr 01 2017 07:20
Hmmm ... let me try it on Codewars right now ...
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:20

'''
function descendingOrder(n){
var splt = n.toString().split('');
var sec = splt.sort();
var result = sec.reverse();
var last = result.join('');

return last;

}
'''

Anika Erceg
@AnikaErceg
Apr 01 2017 07:22
I would debug it myself but I'm not in a positon to use a pc right now (read, I'm too lazy to get out of the bed :D)
Donald Sebastian Leung
@DonaldKellett
Apr 01 2017 07:22
Actually @AnikaErceg it appears that you are right - Test.assertEquals was probably recently improved to use strict comparison === instead of loose comparison ==
@PhillipSchmidt__twitter convert final into a Number before returning
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:22
Copy that.
Anika Erceg
@AnikaErceg
Apr 01 2017 07:24
Did you make it work @PhillipSchmidt__twitter
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:25
I am trying. I should use "parseInt(last);" right?
Donald Sebastian Leung
@DonaldKellett
Apr 01 2017 07:25
Yep, that would work. I would recommend the shorthand though: +final :wink:
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:26
Lol I dont know what you mean?
Donald Sebastian Leung
@DonaldKellett
Apr 01 2017 07:26
Prepending a + to a string value converts it into a Number
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:28
Okay I am very new to all the verbiage. parseInt(+last);?
Anika Erceg
@AnikaErceg
Apr 01 2017 07:28
Nono
Just +last
return +last
Think of it as a shorter version of parseInt()
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:29
Got it! Thank you so much! I can go to sleep now. LOL
Anika Erceg
@AnikaErceg
Apr 01 2017 07:29
Glad to help; rest well
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:29
I have my Hack Reactor live interview on Tuesday. Cramming everyday.
Thank you @DonaldKellett as well
Anika Erceg
@AnikaErceg
Apr 01 2017 07:30
Good luck! :D
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 07:30
Thank you
Anika Erceg
@AnikaErceg
Apr 01 2017 07:31
Anytime ;)
Donald Sebastian Leung
@DonaldKellett
Apr 01 2017 07:32
You're welcome @PhillipSchmidt__twitter :smile:
Oh, and good luck for your interview :smile:
Unknown
@Unknownhezipaz
Apr 01 2017 21:49

$User_FName = $_POST['U_fname'];
I want to know if the explanation below for the code above is right and if I can add to it

//superglobal variable captures the value passed by form and store in local variable it is created when you use the post method in form to get the value that is entered in the form called u_fname.

Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 22:50
stuck on an 8 kata XD

Rock Paper Scissors:'''
const rps = (p1, p2) => {

//Scissors vs Paper
if (p1 = 'rock'){
if (p2 = 'scissors'){
return 'Player 1 won!'
} else if (p2 = 'paper'){
return 'Player 2 won!'
} else {
return 'Draw!'

}
}

//Scissors vs Rock
if (p1 = 'scissors'){
if (p2 = 'paper'){
return 'Player 1 won!'
} else if (p2 = 'rock'){
return 'Player 2 won!'
} else {
return 'Draw'
}
}
}

Rock Paper Scissors:'''
const rps = (p1, p2) => {

//Scissors vs Paper
if (p1 = 'rock'){
if (p2 = 'scissors'){
return 'Player 1 won!'
} else if (p2 = 'paper'){
return 'Player 2 won!'
} else {
return 'Draw!'

}
}

//Scissors vs Rock
if (p1 = 'scissors'){
if (p2 = 'paper'){
return 'Player 1 won!'
} else if (p2 = 'rock'){
return 'Player 2 won!'
} else {
return 'Draw'
}
}
}
'''

Anika Erceg
@AnikaErceg
Apr 01 2017 22:56
I solved that one in python with the same approach as you did :D
What do you get? I mean, why is it failing?
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 22:59
Lol that is why I am here.
Getting 32 passed 27 failed...
Anika Erceg
@AnikaErceg
Apr 01 2017 22:59
Can you see for what test's is it failing?
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 23:00
rock paper scissors
  player 1 win
✔ Test Passed: Value == 'Player 1 won!'
✔ Test Passed: Value == 'Player 1 won!'Expected: 'Player 1 won!', instead got: undefined
 Completed in 2ms
  player 2 win
✔ Test Passed: Value == 'Player 2 won!'Expected: 'Player 2 won!', instead got: undefined
✔ Test Passed: Value == 'Player 2 won!'
 Completed in 1ms
  draw
✔ Test Passed: Value == 'Draw!'Expected: 'Draw!', instead got: 'Draw'Expected: 'Draw!', instead got: undefined
  random
✔ Test Passed: Value == 'Player 1 won!'Expected: 'Draw!', instead got: undefined
✔ Test Passed: Value == 'Draw!'Expected: 'Player 1 won!', instead got: undefined
✔ Test Passed: Value == 'Player 2 won!'Expected: 'Draw!', instead got: undefined
✘ Expected: 'Player 1 won!', instead got: undefined
✔ Test Passed: Value == 'Player 2 won!'
✔ Test Passed: Value == 'Draw!'
✔ Test Passed: Value == 'Player 2 won!'
✔ Test Passed: Value == 'Player 1 won!'
✔ Test Passed: Value == 'Player 2 won!'
✔ Test Passed: Value == 'Player 1 won!'Expected: 'Player 2 won!', instead got: undefined
✔ Test Passed: Value == 'Player 1 won!'
✔ Test Passed: Value == 'Draw!'Expected: 'Player 1 won!', instead got: undefined
✔ Test Passed: Value == 'Player 2 won!'Expected: 'Player 1 won!', instead got: undefined
✘ Expected: 'Player 1 won!', instead got: undefined
✔ Test Passed: Value == 'Player 1 won!'Expected: 'Player 2 won!', instead got: undefined
✔ Test Passed: Value == 'Player 2 won!'Expected: 'Draw!', instead got: 'Draw'Expected: 'Player 2 won!', instead got: undefined
✔ Test Passed: Value == 'Player 1 won!'Expected: 'Player 2 won!', instead got: undefined
✔ Test Passed: Value == 'Player 2 won!'
✔ Test Passed: Value == 'Player 2 won!'Expected: 'Player 2 won!', instead got: undefined
✘ Expected: 'Draw!', instead got: 'Draw'
✔ Test Passed: Value == 'Draw!'Expected: 'Draw!', instead got: 'Draw'Expected: 'Player 2 won!', instead got: undefined
✔ Test Passed: Value == 'Player 2 won!'Expected: 'Player 2 won!', instead got: undefined
✔ Test Passed: Value == 'Player 1 won!'Expected: 'Draw!', instead got: undefined
✔ Test Passed: Value == 'Player 1 won!'
✔ Test Passed: Value == 'Draw!'
✔ Test Passed: Value == 'Player 1 won!'
✔ Test Passed: Value == 'Player 1 won!'Expected: 'Player 1 won!', instead got: undefined
✘ Expected: 'Player 1 won!', instead got: undefined
✘ Expected: 'Draw!', instead got: undefined
✔ Test Passed: Value == 'Player 2 won!'
✔ Test Passed: Value == 'Player 1 won!'Expected: 'Player 2 won!', instead got: undefined
✘ Expected: 'Player 1 won!', instead got: undefined
✔ Test Passed: Value == 'Draw!'
lol
Lol I just got it up to 41 passed and 18 failed
Anika Erceg
@AnikaErceg
Apr 01 2017 23:02
Try changing = to ==
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 23:02
okay
dropped it to 39 passed
Anika Erceg
@AnikaErceg
Apr 01 2017 23:03
tests are random, so it doesn't matter
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 23:03
const rps = (p1, p2) => {

//Rock vs Scissors
if (p1 === 'rock'){
  if (p2 === 'scissors'){
  return 'Player 1 won!'  
  } else if (p2 === 'paper'){
  return 'Player 2 won!'
  } else {
  return 'Draw!'

  }
}

//Scissors vs Paper
if (p1 === 'scissors'){
  if (p2 === 'paper'){
  return 'Player 1 won!'
  } else if (p2 === 'rock'){
  return 'Player 2 won!'
  } else {
  return 'Draw!'
  }
  }
  }
Well they are running 4 different types of tests on this one.
Player 1 wins(1), Player 2 wins (2), Draw(3), Random(4)
Anika Erceg
@AnikaErceg
Apr 01 2017 23:04
If you want to go with that approach, eliminate option for draw right away
instead of testing it in every step
Anika Erceg
@AnikaErceg
Apr 01 2017 23:09
Then go step by step for each option. (also, it might not be a big of a deal here, add ; at the end of the lines)
One more tip, when you solve it, analyze other solutions. Some are really interesting : )
Anika Erceg
@AnikaErceg
Apr 01 2017 23:15
Anyway, would like to stay and help more but my bed is calling me. Good luck! ;)
Phillip Schmidt
@PhillipSchmidt__twitter
Apr 01 2017 23:15
Thank you
Anika Erceg
@AnikaErceg
Apr 01 2017 23:16
I could've been of more help; perhaps next time I will :D