How to return letters from UTF-16
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I need to return the letters in a word in alphabetical order. I got the following problem, I don't know how to return the letters from numbers, I tried to use String.fromCharCode()
and charAt()
but it did nothing.
I got:
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(order => order.charCodeAt()).sort((a,b) => b - a).reverse();
return res;
}
So the result is [ 98, 99, 100, 101, 101, 111, 114, 116, 121 ]
javascript
add a comment |
I need to return the letters in a word in alphabetical order. I got the following problem, I don't know how to return the letters from numbers, I tried to use String.fromCharCode()
and charAt()
but it did nothing.
I got:
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(order => order.charCodeAt()).sort((a,b) => b - a).reverse();
return res;
}
So the result is [ 98, 99, 100, 101, 101, 111, 114, 116, 121 ]
javascript
please ask your question little bit clearly
– Muthusamy
Jan 3 at 4:38
How to change numbers in an array to the letters through utf 16
– Ilya Solodeev
Jan 3 at 4:43
add a comment |
I need to return the letters in a word in alphabetical order. I got the following problem, I don't know how to return the letters from numbers, I tried to use String.fromCharCode()
and charAt()
but it did nothing.
I got:
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(order => order.charCodeAt()).sort((a,b) => b - a).reverse();
return res;
}
So the result is [ 98, 99, 100, 101, 101, 111, 114, 116, 121 ]
javascript
I need to return the letters in a word in alphabetical order. I got the following problem, I don't know how to return the letters from numbers, I tried to use String.fromCharCode()
and charAt()
but it did nothing.
I got:
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(order => order.charCodeAt()).sort((a,b) => b - a).reverse();
return res;
}
So the result is [ 98, 99, 100, 101, 101, 111, 114, 116, 121 ]
javascript
javascript
asked Jan 3 at 4:35


Ilya SolodeevIlya Solodeev
33
33
please ask your question little bit clearly
– Muthusamy
Jan 3 at 4:38
How to change numbers in an array to the letters through utf 16
– Ilya Solodeev
Jan 3 at 4:43
add a comment |
please ask your question little bit clearly
– Muthusamy
Jan 3 at 4:38
How to change numbers in an array to the letters through utf 16
– Ilya Solodeev
Jan 3 at 4:43
please ask your question little bit clearly
– Muthusamy
Jan 3 at 4:38
please ask your question little bit clearly
– Muthusamy
Jan 3 at 4:38
How to change numbers in an array to the letters through utf 16
– Ilya Solodeev
Jan 3 at 4:43
How to change numbers in an array to the letters through utf 16
– Ilya Solodeev
Jan 3 at 4:43
add a comment |
2 Answers
2
active
oldest
votes
By default, .sort()
already orders values by their UTF-16 string representation.
The default sort order is built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
function AlphabetSoup(str) {
return str.split('').sort();
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
If you were insistent upon using your proposed method, you could re-map
the values back to their string representation using String.fromCharCode()
.
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl
.map(order => order.charCodeAt())
.sort((a, b) => a-b)
.map(order => String.fromCharCode(order));
return res;
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
add a comment |
console.log(AlphabetSoup('hello'))
console.log(AlphabetSoup2('hello'))
/* Given what you gave, you have to convert it back */
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(char => char.charCodeAt())
.sort((a, b) => b - a)
.reverse()
.map(ascii=>String.fromCharCode(ascii)) // <-- convert back
.join(''); // <-- make it a string
return res;
}
/* Of course string comparison natively works on ASCII values */
function AlphabetSoup2(str) {
let arr = str.split('');
return arr.sort((a, b) => b < a).join(''); // <-- notice the '<'
}
Of course, sort()
be default does what you want so you could be less explicit (and more accurate) by doing return arr.sort().join('')
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016401%2fhow-to-return-letters-from-utf-16%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
By default, .sort()
already orders values by their UTF-16 string representation.
The default sort order is built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
function AlphabetSoup(str) {
return str.split('').sort();
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
If you were insistent upon using your proposed method, you could re-map
the values back to their string representation using String.fromCharCode()
.
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl
.map(order => order.charCodeAt())
.sort((a, b) => a-b)
.map(order => String.fromCharCode(order));
return res;
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
add a comment |
By default, .sort()
already orders values by their UTF-16 string representation.
The default sort order is built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
function AlphabetSoup(str) {
return str.split('').sort();
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
If you were insistent upon using your proposed method, you could re-map
the values back to their string representation using String.fromCharCode()
.
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl
.map(order => order.charCodeAt())
.sort((a, b) => a-b)
.map(order => String.fromCharCode(order));
return res;
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
add a comment |
By default, .sort()
already orders values by their UTF-16 string representation.
The default sort order is built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
function AlphabetSoup(str) {
return str.split('').sort();
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
If you were insistent upon using your proposed method, you could re-map
the values back to their string representation using String.fromCharCode()
.
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl
.map(order => order.charCodeAt())
.sort((a, b) => a-b)
.map(order => String.fromCharCode(order));
return res;
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
By default, .sort()
already orders values by their UTF-16 string representation.
The default sort order is built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
function AlphabetSoup(str) {
return str.split('').sort();
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
If you were insistent upon using your proposed method, you could re-map
the values back to their string representation using String.fromCharCode()
.
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl
.map(order => order.charCodeAt())
.sort((a, b) => a-b)
.map(order => String.fromCharCode(order));
return res;
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
function AlphabetSoup(str) {
return str.split('').sort();
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
function AlphabetSoup(str) {
return str.split('').sort();
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl
.map(order => order.charCodeAt())
.sort((a, b) => a-b)
.map(order => String.fromCharCode(order));
return res;
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl
.map(order => order.charCodeAt())
.sort((a, b) => a-b)
.map(order => String.fromCharCode(order));
return res;
}
var r = AlphabetSoup("HelloWorld");
console.log(r);
answered Jan 3 at 4:46


Tyler RoperTyler Roper
14.4k32142
14.4k32142
add a comment |
add a comment |
console.log(AlphabetSoup('hello'))
console.log(AlphabetSoup2('hello'))
/* Given what you gave, you have to convert it back */
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(char => char.charCodeAt())
.sort((a, b) => b - a)
.reverse()
.map(ascii=>String.fromCharCode(ascii)) // <-- convert back
.join(''); // <-- make it a string
return res;
}
/* Of course string comparison natively works on ASCII values */
function AlphabetSoup2(str) {
let arr = str.split('');
return arr.sort((a, b) => b < a).join(''); // <-- notice the '<'
}
Of course, sort()
be default does what you want so you could be less explicit (and more accurate) by doing return arr.sort().join('')
add a comment |
console.log(AlphabetSoup('hello'))
console.log(AlphabetSoup2('hello'))
/* Given what you gave, you have to convert it back */
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(char => char.charCodeAt())
.sort((a, b) => b - a)
.reverse()
.map(ascii=>String.fromCharCode(ascii)) // <-- convert back
.join(''); // <-- make it a string
return res;
}
/* Of course string comparison natively works on ASCII values */
function AlphabetSoup2(str) {
let arr = str.split('');
return arr.sort((a, b) => b < a).join(''); // <-- notice the '<'
}
Of course, sort()
be default does what you want so you could be less explicit (and more accurate) by doing return arr.sort().join('')
add a comment |
console.log(AlphabetSoup('hello'))
console.log(AlphabetSoup2('hello'))
/* Given what you gave, you have to convert it back */
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(char => char.charCodeAt())
.sort((a, b) => b - a)
.reverse()
.map(ascii=>String.fromCharCode(ascii)) // <-- convert back
.join(''); // <-- make it a string
return res;
}
/* Of course string comparison natively works on ASCII values */
function AlphabetSoup2(str) {
let arr = str.split('');
return arr.sort((a, b) => b < a).join(''); // <-- notice the '<'
}
Of course, sort()
be default does what you want so you could be less explicit (and more accurate) by doing return arr.sort().join('')
console.log(AlphabetSoup('hello'))
console.log(AlphabetSoup2('hello'))
/* Given what you gave, you have to convert it back */
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(char => char.charCodeAt())
.sort((a, b) => b - a)
.reverse()
.map(ascii=>String.fromCharCode(ascii)) // <-- convert back
.join(''); // <-- make it a string
return res;
}
/* Of course string comparison natively works on ASCII values */
function AlphabetSoup2(str) {
let arr = str.split('');
return arr.sort((a, b) => b < a).join(''); // <-- notice the '<'
}
Of course, sort()
be default does what you want so you could be less explicit (and more accurate) by doing return arr.sort().join('')
console.log(AlphabetSoup('hello'))
console.log(AlphabetSoup2('hello'))
/* Given what you gave, you have to convert it back */
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(char => char.charCodeAt())
.sort((a, b) => b - a)
.reverse()
.map(ascii=>String.fromCharCode(ascii)) // <-- convert back
.join(''); // <-- make it a string
return res;
}
/* Of course string comparison natively works on ASCII values */
function AlphabetSoup2(str) {
let arr = str.split('');
return arr.sort((a, b) => b < a).join(''); // <-- notice the '<'
}
console.log(AlphabetSoup('hello'))
console.log(AlphabetSoup2('hello'))
/* Given what you gave, you have to convert it back */
function AlphabetSoup(str) {
let spl = str.split('');
let res = spl.map(char => char.charCodeAt())
.sort((a, b) => b - a)
.reverse()
.map(ascii=>String.fromCharCode(ascii)) // <-- convert back
.join(''); // <-- make it a string
return res;
}
/* Of course string comparison natively works on ASCII values */
function AlphabetSoup2(str) {
let arr = str.split('');
return arr.sort((a, b) => b < a).join(''); // <-- notice the '<'
}
answered Jan 3 at 4:50
vol7ronvol7ron
25.6k1687152
25.6k1687152
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016401%2fhow-to-return-letters-from-utf-16%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
please ask your question little bit clearly
– Muthusamy
Jan 3 at 4:38
How to change numbers in an array to the letters through utf 16
– Ilya Solodeev
Jan 3 at 4:43