GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • LeetCodeJavascript.com
  • Star on GitHub

This view

  • Original page
  • New address

GeezerVison is showing leetcodejavascript.com — #1309 - Decrypt String from Alphabet to Integer Mapping - LeetCode JavaScript Solutions

Back to all solutions

#1309 - Decrypt String from Alphabet to Integer Mapping

Easy • View on LeetCode • View on GitHub
String

Problem Description

Given a string s formed by digits ('0' - '9') and '#' .

We want to map s to English lowercase characters as follows:

  • Characters ('a' to 'i') are represented by ('1' to '9') respectively.
  • Characters ('j' to 'z') are represented by ('10#' to '26#') respectively.

Return the string formed after mapping.

It's guaranteed that a unique mapping will always exist.

Solution

/**
 * @param {string} s
 * @return {string}
 */
var freqAlphabets = function(s) {
  return s.replace(/\d{2}#|\d/g, match => {
    return String.fromCharCode('a'.charCodeAt() + parseInt(match, 10) - 1);
  });
};
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.