+ 7

Tried over a dozen times to get input to split no luck.

It works for individually letters and the strings added for examples how do I need to phrase the split join to work with this? https://code.sololearn.com/WG17dDhRUw6N/?ref=app

5th Jan 2018, 7:43 PM
bobbie
bobbie - avatar
23 Antworten
+ 10
your approach is not quite there... consider this one: create a map of uppercase letters like so var letterMap = { "A": "🙂", "B": "🤓", ...... } now you can evaluate the input and create the encrypted word like so: var word = inputText.toUpperCase(); var encrypted = ""; for(var i = 0; i < word.length; i++){ encrypted += letterMap[word[i]] || word[i]; // the OR condition should take care of values not in the map (spaces for example) by simply putting the original value }
5th Jan 2018, 7:52 PM
Burey
Burey - avatar
+ 14
decrypting is a bit of an issue with emojis.... as the breakdown for individual emojis from a string of emojis fails but i found a solution online for this: https://stackoverflow.com/questions/24531751/how-can-i-split-a-string-containing-emoji-into-an-array first declare a function which breaks a string to array of emojis: var emojiStringToArray = function (str) { split = str.split(/([\uD800-\uDBFF][\uDC00-\uDFFF])/); arr = []; for (var i=0; i<split.length; i++) { char = split[i] if (char !== "") { arr.push(char); } } return arr; }; and replace the for loop with map on the returned array: emojiStringToArray(word).map(function(emoji,ind){ decrypted += letterMap1[emoji] || emoji; });
6th Jan 2018, 8:25 AM
Burey
Burey - avatar
+ 11
great, will be waiting for results :p
5th Jan 2018, 8:14 PM
Burey
Burey - avatar
+ 9
first of all, move the letter map outside of the function, no need for it to be inside secondly, after using getElementById(..) you also need the value, so change it to getElementById(..).value and lastly, you'd want to put the output somewhere, so i assume that,s what the <p> is for? document.getElementById("a").innerHTML = encrypted; should do the trick
5th Jan 2018, 10:01 PM
Burey
Burey - avatar
+ 8
Thanks for the detailed explanation Morpheus I noticed it was considering an emoji as more than a single character I now know why. If you can help fix the original switch method that would be awesome I love how there are many ways to accomplish things in coding.
6th Jan 2018, 3:53 PM
bobbie
bobbie - avatar
+ 7
Thank you Burey I tried a map method before this hopefully your advice will make it work.
5th Jan 2018, 8:13 PM
bobbie
bobbie - avatar
+ 7
Thank you again Burey you are awesome!!! I appreciate all the work you put into this. 🙂
6th Jan 2018, 3:49 PM
bobbie
bobbie - avatar
+ 6
Having no luck with this either what am I missing? https://code.sololearn.com/WBBI9t8YP9E2/?ref=app
5th Jan 2018, 9:48 PM
bobbie
bobbie - avatar
+ 6
Thanks Burey you are a genius it's running now just gotta fancy it up. Thank you so much!!!
5th Jan 2018, 11:21 PM
bobbie
bobbie - avatar
+ 6
Decrypt not going as planned lol any possible solutions will be appreciated.
6th Jan 2018, 12:06 AM
bobbie
bobbie - avatar
+ 6
in case function provided by Burey is unclear, here's the breakdown java script uses utf16 character encoding of 16 bits for simple characters , but emojis need 20 bits ,for example A is 0041 in hexadecimal ( 16 bits) but 😁 is 1F600 in hexadecimal ( 20 bits), so , to handle emojis we break 20 bits in a way of two 16 and 16 bits called surrogate pairs , so that we can use them in utf-16 mode, example 😁 1F600(20 bits) is broken to D838 and DE00, both 16 bits, used side by side to make 😁, can try this on ur console to be sure "\uD838\uDE00" gives output 😁 String.fromCodePoint(0x1F600) also gives output 😁 now back to ur issue , try checking this on ur js console "😁". length and it will return 2 instead of 1 , so emojis are made up of 2 characters instead of 1 in utf-16. Bobbie when I give input of 🤓🤓🤓 in ur decryption area, you know the loop runs actually 6 times instead of 3 in ur function1, moreover emojis are not even read hence they are undefined , and the backup part - || words[ i ] simply returns the user input without decryption. so there's 2 ways to solve ur problem first the fundamental , awesome to know but complex way as provided by Burey or a simple way , of a separate switch block in ur function1 for every emojis,
6th Jan 2018, 1:47 PM
Morpheus
Morpheus - avatar
+ 6
Bobbie this doubt of yours made me learn so many new stuff s , it's amazing to know , awesome use of my whole last night
6th Jan 2018, 1:48 PM
Morpheus
Morpheus - avatar
+ 6
finally I am at peace with this problem with a perfect one liner solution, ditch the switch, ditch the regex , ditch the function Behold the ES6 voodoo for emoji parsers. ######################### [..."😁🤓😁🤓😍🤓😍🤓🤓"] ######################### that's it , https://code.sololearn.com/WroSj17hdHKG/?ref=app
6th Jan 2018, 5:26 PM
Morpheus
Morpheus - avatar
+ 6
[..." Ur emoji string here" ] , this syntax parses emojees into arrays that's it now u have a emoji array, and no need to worry about layers and layers of regex , or about codepoints for various emojis!, just need ES6 supported browsers, that mostly are, thx to burray for that stackoverflow link
6th Jan 2018, 5:29 PM
Morpheus
Morpheus - avatar
+ 6
@Bobbie, this code is a strong contender for COTD , because of it cool concept, simple code, yet with subtle complexities involved in implementation. I learned few simple but effective tricks like better way to use inputs and to use || this for fallback , since coming from c and C ++ background , I couldn't follow ES features in my coding practice
6th Jan 2018, 5:45 PM
Morpheus
Morpheus - avatar
+ 6
Awesome Morpheus I would love a team to try to conquer this Burey is busy with work and all but I assured him if we get this up and running and it becomes profitable he will not be forgotten. Are you on Discord or Slack so we can chat more?
6th Jan 2018, 9:04 PM
bobbie
bobbie - avatar
+ 6
https://code.sololearn.com/W7tzIp4lAI8C/?ref=app The links are in the comments the 1St Slack link expired but there is a newer one after.
6th Jan 2018, 9:16 PM
bobbie
bobbie - avatar
+ 5
Great job Morpheus!!! I will try to work out a new design with your idea to show off how many ways there are to accomplish things with code!!! This SoloLearn is a great TeamLearn!!! Thanks again!!! 🙂
6th Jan 2018, 5:58 PM
bobbie
bobbie - avatar
+ 5
Morpheus do you have app building experience? I think this might make a fun one. I have been trying but my Android Studio continues to have gradle issues.
6th Jan 2018, 8:21 PM
bobbie
bobbie - avatar
+ 5
Bobbie , I know only in theories and some videos , haven't actually done it yet , but how tough can it be , we ll figure it out! just keep sharing the issues and progress we ll eventually get there
6th Jan 2018, 9:01 PM
Morpheus
Morpheus - avatar