#Sorting Fruits - how do emoji's comparision work?

1 messages ยท Page 1 of 1 (latest)

loud parcel
#

So I've only used standard variable types in comparison functions (ints, floats, bools, strings, etc) - and this was my first time using code that looked like: fruit[i] === "๐ŸŽ"

I first tried with a for loop like this:

for(fr in fruit) - and tried to compare fr to "๐ŸŽ" - this didn't work

but for(i=0;i<fruit.length;i++) and fruit[i] === "๐ŸŽ" worked.

Anyone able to help me understand why one type of for loop works and the other doesn't?

And how is the emoji actually being parsed?

inner fjord
#

A for..in loop on an array will iterate the indexes of the array, not the elements. If you want to iterate the array elements, you'd want to use a for..of loop. Also, emojis are character sequences, so they are effectively the string type in JavaScript.

night pivot
#

We have so many loop types. if all you are doing is finding a specfic fruit a loop is not required. You can use indexOf property of the array or includes.
const fruit = ['๐ŸŽ']; console.log(fruit.indexOf('๐ŸŽ')) console.log(fruit.includes('๐ŸŽ'))

inner fjord
#

A discussion of Fruit Loops... ๐Ÿ˜†

night pivot
night pivot
# loud parcel So I've only used standard variable types in comparison functions (ints, floats,...

like @inner fjord mentioned they are still strings starting with : and ending with : . these can be removed from the string and your apple will just say apple.
Strings them self's are encoded into a human readable format. Most websites/text editors use UTF-8 format https://en.wikipedia.org/wiki/UTF-8
Javascript can also decode & encode binary strings (1s and 0s) into human readable formats.

UTF-8 is a variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from Unicode (or Universal Coded Character Set) Transformation Format โ€“ 8-bit.UTF-8 is capable of encoding all 1,112,064 valid character code points in Unicode using one to four one-byte (8-bit) code units. Code ...