I have the following code:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const input = 'hello world';
document.getElementById("demo").innerHTML = sortAlphabets(input);
function sortAlphabets(input) {
return input.split('').sort().join('');
};
</script>
</body>
</html>
The result is: dehllloorw
But I want to change it to sort by character appearance position. The result should be: hellloowrd
How can I do that?
Really appreciated.
Thank you.