Is it an emoji?

17

I've been working on this iOS app recently and I encountered a (rather easily solved) problem: How do I determine if my string is comprised only of emojis?

Well, that's your job today!

Input

A string. If the presence of unicode characters is problematic for you then you may use a different reasonable format. Please state what you do if you do something different from a regular string for taking input.

Output

Print or return a truthy value if the input string contains only emojis, and a falsey value if it contains any characters other than emojis.

Wait a sec... what's an emoji?

An emoji is a character that falls in these ranges:

0x1F600...0x1F64F  // Emoticons
0x1F300...0x1F5FF  // Misc Symbols and Pictographs
0x1F680...0x1F6FF  // Transport and Map
0x2600...0x26FF    // Misc symbols
0x2700...0x27BF    // Dingbats
0xFE00...0xFE0F    // Variation Selectors

(I think)

This is , so shortest code in bytes wins❕

Test cases

"Is it an emoji? " -> False
"code-golf" -> False
"    " -> False
"I have no fancy emojis :(" -> False

"" -> True
"" -> True

For you poor souls who cannot see emojis, here is an image of the test cases.

Daniel

Posted 2016-12-07T00:08:18.920

Reputation: 6 425

2Perhaps include a version (maybe an image) for those who can't see emojis? ;-) – ETHproductions – 2016-12-07T00:10:11.580

@ETHproductions, do you suggest I link to a photo of the test cases or something else? – Daniel – 2016-12-07T00:12:07.483

Well, there are emojis spread throughout the whole question, but I guess the only really important ones are in the test cases, so an image of just the test cases will work. – ETHproductions – 2016-12-07T00:14:00.713

@ETHproductions, I added a link to a photo of the test cases – Daniel – 2016-12-07T00:22:47.437

Can input be a numeric array of Unicode code points? Also, what range of characters/numbers can the input contain? – Luis Mendo – 2016-12-07T00:24:55.947

@LuisMendo, I suppose you can take an array of Unicode code points. The range of characters is the range I have above in the question in addition to any printable ASCII character. – Daniel – 2016-12-07T00:33:30.307

I'm going to vote to re-open. I don't see a valid reason as to why this is unclear. If a string contains only emojis, it's a truthy. if not, it's a falsy. – tuskiomi – 2017-08-15T16:05:07.907

You forgot some emoji: vomiting emoji, combining bloodstain

– mbomb007 – 2017-08-15T16:44:19.777

Answers

2

Ruby, 61 56+1 = 62 57 47 bytes

Uses the -n flag and takes input from STDIN. Prints 0 for truthy and nil for falsy.

-5 bytes because for some reason I initially thought the regex solution would not work???

-10 bytes from NieDzejkob for noticing a code point overlap that I missed :o

p$_=~/^[--☀-➿︀-︀️]*$/

Try it online!

Value Ink

Posted 2016-12-07T00:08:18.920

Reputation: 10 608

147 bytes if you merge two ranges in the regex. – NieDzejkob – 2017-12-11T19:40:47.353

1That's 47 isn't it? – Asone Tuhid – 2018-01-22T09:24:10.017

Yeah I forgot to update the score after getting the suggestion from @NieDzejkob – Value Ink – 2018-01-25T09:25:35.243

10

Emojicode, 179 bytes

a➡na◀n 9728▶n 10175◀n 65024▶n 65039◀n 127744▶n 128591◀n 128640▶n 12876701

A callable that takes a list of integers representing the codepoints and returns 1 or 0.

Try it online!

Emojicode, 187 bytes

a➡iani◀n 9728▶n 10175◀n 65024▶n 65039◀n 127744▶n 128591◀n 128640▶n 128767

A callable that takes a string and returns a boolean.

Try it online!

Ungolfed and explained

 A callable that takes a  called input and returns a 
 input  ➡ 
  For each character in input
  character  input 
   Create a frozen called n containing the unicode codepoint of character
   n  character
   If the value is in one of specific ranges, return  (if the current character is not an emoji)
  ◀n 9728▶n 10175◀n 65024▶n 65039◀n 127744▶n 128591◀n 128640▶n 128767
    
  
 
  Since we're here, all characters are an emoji, so return 
 

Try it online!

NieDzejkob

Posted 2016-12-07T00:08:18.920

Reputation: 4 630

1

JavaScript, 83 61 bytes

-22 bytes thanks to @Shaggy

s=>(s.match(/\ud83d[\ude00-\ude4f]/g)||"").length==s.length/2

Demo

f=s=>(s.match(/\ud83d[\ude00-\ude4f]/g)||"").length==s.length/2

document.writeln(f("code-golf")) //false
document.writeln(f("    ")) //false
document.writeln(f("I have no fancy emojis :(")) //false
document.writeln(f("")) //true
document.writeln(f("")) //true

Oliver

Posted 2016-12-07T00:08:18.920

Reputation: 7 160

161 bytes: s=>(s.match(/\ud83d[\ude00-\ude4f]/g)||"").length==s.length/2 – Shaggy – 2017-08-15T15:46:16.970

Uh, how does this work? The regex doesn't specify the codepoints of any emoji... – NieDzejkob – 2017-12-11T19:40:13.783

@NieDzejkob I believe JS uses UTF-16 for Unicode, so I guess these are the UTF-16 byte representations of those codepoints. The answer is incomplete though, it fails for , `♔☺☠`, etc., all of which should be truthy. It seems to check only for one range out of the six that OP mentions. – sundar - Reinstate Monica – 2018-07-10T20:30:29.703

1

Python, 87 bytes

lambda x:re.match('^[---☀-➿︀-︀️]*$',x)and 1
import re

Try it online!

Returns 1 as truthy value and None as falsy value.

Uriel

Posted 2016-12-07T00:08:18.920

Reputation: 11 708

I "borrowed" your regex, hope you don't mind ;) – HyperNeutrino – 2017-08-15T18:29:36.633

Since I told Value Ink about it, I'll tell you too - the first two groups in the regex can be merged because of adjacent codepoints: - – NieDzejkob – 2017-12-11T19:42:27.987

1

Proton, 54 bytes

map(/[--☀-➿︀-︀️]/.match)+all

Try it online!

-9 bytes (3 chars) thanks to NieDzejkob

"Borrowing" Uriel's regex :P This is shorter thanks to Proton's obscure features and regex literals

HyperNeutrino

Posted 2016-12-07T00:08:18.920

Reputation: 26 575

As I told Value Ink, the first two groups in the regex can be merged because of adjacent codepoints: - – NieDzejkob – 2017-12-11T19:42:52.370

like this

– NieDzejkob – 2017-12-12T06:27:18.810

0

QuadR, 47 bytes

''≡⍵
[--☀-➿︀-︀️]

Try it online!

Is…

''≡⍵ an empty string identical to the result when…

[--☀-➿︀-︀️] all emojis are…

 replaced with nothing

?

Adám

Posted 2016-12-07T00:08:18.920

Reputation: 37 779