JavaScript: Find all the possible options to replace the hash in a string
JavaScript Basic: Exercise-116 with Solution
Replace Hash in String to Make Divisible by 3
Write a JavaScript program to find all the possible options to replace the hash in a string (Consists of digits and one hash (#)) with a digit to produce an integer divisible by 3.
For a string "2*0", the output should be : ["210", "240", "270"]
Sample Solution:
JavaScript Code:
Output:
["210","240","270"] ["402","432","462","492"]
Live Demo:
Flowchart:

ES6 Version:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that replaces a hash in a numeric string with digits 0–9 to yield a number divisible by 3.
- Write a JavaScript function that iterates through possible digit replacements for a hash placeholder and returns valid combinations divisible by 3.
- Write a JavaScript program that uses modular arithmetic to test each replacement for a hash in a string and outputs all options yielding divisibility by 3.
Improve this sample solution and post your code through Disqus.
Previous: JavaScript program to check whether a matrix is a diagonal matrix or not.
Next: JavaScript program to check if a given matrix is an identity matrix.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.