Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Your job is to clear the text from any unnecessary symbols (only the numbers are needed) and convert
- the remaining number sequences to hex format. If a hex value has less than 4 characters, you need to add
- leading zeros. Finally, you need to place a "0x" prefix before each hex value and concatenate them all with
- dashes '-'. The input data will be received as an array. It contains one argument – the initial message
- you need to transform. The output consists of only one line – the transformed message. */
- function transformMessage(arr) {
- var numbers = arr[0].split(/[^0-9]+/g).filter(Boolean);
- for (var i = 0; i < numbers.length; i += 1) {
- var hex = Number(numbers[i]).toString(16).toUpperCase();
- while (hex.length < 4) {
- hex = '0'.concat(hex);
- }
- numbers[i] = '0x'.concat(hex);
- }
- return numbers.join('-');
- }
- console.log(transformMessage(['5tffwj(//*7837xzc2---34rlxXP%$”.']));
- console.log(transformMessage(['482vMWo(*&^%$213;k!@41341((()&^>><///]42344p;e312']));
- console.log(transformMessage(['20']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement