📜 ⬆️ ⬇️

You can not solve this problem at the interview

Hi, Habr. I want to share with you one interesting task that many of us received at the interview, but probably did not even realize that we were solving it incorrectly.

First of all - a little history. While working at the positions of the team leader and the technical officer, I sometimes had to conduct interviews, respectively, it is necessary to prepare several theoretical questions, well, a couple of simple tasks, the solution of which should not have taken more than 2–3 minutes. If everything is simple with theory - my favorite question is: “what is typeof null equal to?”, By answering you can immediately understand who is sitting in front of you, June - just answer correctly, and the claimant to seniera will also explain why. That with practice - more difficult. For a long time I could not come up with a normal task, not a crawler, like a fizz-buzz, but something of my own. Therefore, I gave assignments during the interviews, which I myself had taken when I got a job. About the first of them will be discussed.

Task text


Write a function that accepts a string as input, and returns this string "back to front"

function strReverse(str) {};
strReverse('Habr') === 'rbaH'; // true

, , :

const strReverse = str => str.split('').reverse().join('');

- , «split('')». , : « , ...?». .

, , , emoji! , , , , (, ).
, emoji , .
image

, , . , , , , , , !

image

, , , … , , , emoji ?
, !
image

. , , , , — , .
, . « ?» . «, » — , … « ? ? , — ? !» — .
, , — .

Emoji?


, — ! , .

emoji unicode 8.0 emoji 2.0 , emoji.

.

emoji

image



, emoji

image



emoji, zwj — .
ZERO WIDTH JOINER (ZWJ) — , , emoji ZWJ (200D), «» emoji :
image



, emoji .

, , , ?

.


, .
emoji, , , .


emoji_sequence :=
  emoji_core_sequence
| emoji_zwj_sequence
| emoji_tag_sequence

#   

emoji_core_sequence :=
  emoji_character
| emoji_presentation_sequence
| emoji_keycap_sequence
| emoji_modifier_sequence
| emoji_flag_sequence

emoji_presentation_sequence :=
  emoji_character emoji_presentation_selector
emoji_presentation_selector := \x{FE0F}

emoji_keycap_sequence := [0-9#*] \x{FE0F 20E3}

emoji_modifier_sequence :=
  emoji_modifier_base emoji_modifier
  
emoji_modifier_base := \p{Emoji_Modifier_Base}
emoji_modifier := \p{Emoji_Modifier}
#     

emoji_flag_sequence :=
  regional_indicator regional_indicator

regional_indicator := \p{Regional_Indicator}

emoji_zwj_sequence :=
  emoji_zwj_element ( ZWJ emoji_zwj_element )+
  
emoji_zwj_element :=
  emoji_character
| emoji_presentation_sequence
| emoji_modifier_sequence

emoji_tag_sequence := 
    tag_base tag_spec tag_term
    
tag_base := 
  emoji_character
| emoji_modifier_sequence
| emoji_presentation_sequence
tag_spec := [\x{E0020}-\x{E007E}]+
tag_term := \x{E007F}


, , () , .

Unicode Categories


, , , , , , . . : emoji: {Emoji}, {Emoji_Presentation}, {Emoji_Modifier}, {Emoji_Modifier_Base}, , , , ECMAScript . — — {Emoji}

image

tc-39 (stage-2 10.04.2019).

« , » — github.com/mathiasbynens/emoji-regex, , , … , … , ! !



    const emojiRegex = require('emoji-regex');
    const regex = emojiRegex();
    function stringReverse(string) {
        
        let match;
        const emojis = [];
        const separator = `unique_separator_${Math.random()}`;
        const reversedSeparator = [...separator].reverse().join('');
    
        while (match = regex.exec(string)) {
            const emoji = match[0];
            emojis.push(emoji);
        }
    
        return [...string.replace(regex, separator)].reverse().join('').replace(new RegExp(reversedSeparator, 'gm'), () => emojis.pop());
    
    }
    

image


"" , - , . , : « , , null >= 0? !». , 100% , , - — , . -, , , - .

, , .

:

\u{0415}\u{0308}. , 2 , emoji, … — .

UPD: «», 2 u{0415}() u{0308}("̈), «» .

')

Source: https://habr.com/ru/post/447614/


All Articles