I have ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f
and I want 7fb9c0
....
I am using lodash
and where's what I have so far
mytxid = 'ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f'
reverseTxid = _.chunk mytxid.split(''), 2
reverseTxid = reverseTxid.reverse()
reverseTxid _.flattenDeep reverseTxid
However, I get an error on the .reverse()
: [TypeError: object is not a function]
What am I doing wrong and what's a better way to do it?
I have ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f
and I want 7fb9c0
....
I am using lodash
and where's what I have so far
mytxid = 'ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f'
reverseTxid = _.chunk mytxid.split(''), 2
reverseTxid = reverseTxid.reverse()
reverseTxid _.flattenDeep reverseTxid
However, I get an error on the .reverse()
: [TypeError: object is not a function]
What am I doing wrong and what's a better way to do it?
Share Improve this question edited Mar 12, 2015 at 18:31 Shamoon asked Mar 12, 2015 at 18:24 ShamoonShamoon 43.7k101 gold badges332 silver badges628 bronze badges1 Answer
Reset to default 10You can split the String into bytes by matching every two hex digits, reverse the returned array, then join the array back into a String:
var s = "ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f";
s.match(/[a-fA-F0-9]{2}/g).reverse().join('')
// "7fb9c074116a348dce338e9990da4eb44e3ca852d7090c50970a46e3c2e8d3de"