d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Javascript Help
Add Reply New Topic New Poll
Member
Posts: 12,727
Joined: Aug 19 2004
Gold: 573.00
Mar 17 2014 11:59pm
function compare (a, b) {
console.log(a + " < " + b , a < b);
}

compare('a', 'b');
compare('a', 'A');
compare('apples', 'oranges');
compare('apples', 'applications');
compare('app', 'apples');
compare('hello', 'hello');

I don't get what the "<" i put anyword inside of it and it prints out all the compares but I take it out and only 4 work.

I am also looking for a tutor thank i can ask questions sO i don't have to make a post everytime I need help with something.
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Mar 18 2014 08:08am
Code
"a < b" true
"a < A" false
"apples < oranges" true
"apples < applications" true
"app < apples" true
"hello < hello" false


This is what I got..
Where you expecting anything different?

I'm not really sure what it is you're confused about.

This post was edited by grievance on Mar 18 2014 08:15am
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Mar 19 2014 10:00pm
when comparing strings, its going to compare string length
the first part of the console.log is just giving u a string version of the comparison, not actually comparing them. the second part is the actual function

kind of hard to understand what your asking tho.
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Mar 19 2014 10:10pm
Quote (AkuuZ @ Mar 19 2014 11:00pm)
when comparing strings, its going to compare string length.


This is incorrect. using comparison operators on strings will actually compare them by lexicographical order. It is not just checking length.
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Mar 20 2014 01:57pm
Quote (Minkomonster @ Mar 20 2014 04:10am)
This is incorrect. using comparison operators on strings will actually compare them by lexicographical order. It is not just checking length.


oh right.

"apple" < "z" should return true.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll