Help with understanding of what to use with this question in Javascript: /******************************************************************************* * Problem 2: mask the characters of a password. * * Sometimes we want to show a password, but replace some or all of the * letters with a character like *. This is called masking, and allows us to * hide information, while still displaying something. * * Write a function maskPassword() that takes two arguments: a password to mask, * and a number of characters to show at the start: * * maskPassword('super-secret', 3) * * would return the following string: * * "sup*********" * * Whereas maskPassword('super-secret') or maskPassword('super-secret', 0) * would both return: * * "************" * * @param {String} password - a password to be masked. * @param {Number} charsToShow - (optional) the number of characters to reveal. ******************************************************************************/ function maskPassword(password, charsToShow) { // Your code here... } These are the tests is has to go through to pass: const { maskPassword } = require('./solutions'); describe('Problem 2 - maskPassword() function', function() { test('all characters should be masked by default', function() { let password = 'sUp3rS3kR_t!'; let result = maskPassword(password); expect(result).toBe('************'); }); test('all characters should be masked if charsToMask is 0', function() { let password = '1234567890__'; let result = maskPassword(password, 0); expect(result).toBe('************'); }); test('first 3 characters should be unmasked if requested', function() { let password = 'sUp3rS3kR_t!'; let result = maskPassword(password, 3); expect(result).toBe('sUp*********'); }); test('all characters should be unmasked if requested', function() { let password = '!t_Rk3Sr3pUs'; let result = maskPassword(password, 12); expect(result).toBe(password); }); });
Help with understanding of what to use with this question in Javascript:
/*******************************************************************************
* Problem 2: mask the characters of a password.
*
* Sometimes we want to show a password, but replace some or all of the
* letters with a character like *. This is called masking, and allows us to
* hide information, while still displaying something.
*
* Write a function maskPassword() that takes two arguments: a password to mask,
* and a number of characters to show at the start:
*
* maskPassword('super-secret', 3)
*
* would return the following string:
*
* "sup*********"
*
* Whereas maskPassword('super-secret') or maskPassword('super-secret', 0)
* would both return:
*
* "************"
*
* @param {String} password - a password to be masked.
* @param {Number} charsToShow - (optional) the number of characters to reveal.
******************************************************************************/
function maskPassword(password, charsToShow) {
// Your code here...
}
These are the tests is has to go through to pass:
const { maskPassword } = require('./solutions');
describe('Problem 2 - maskPassword() function', function() {
test('all characters should be masked by default', function() {
let password = 'sUp3rS3kR_t!';
let result = maskPassword(password);
expect(result).toBe('************');
});
test('all characters should be masked if charsToMask is 0', function() {
let password = '1234567890__';
let result = maskPassword(password, 0);
expect(result).toBe('************');
});
test('first 3 characters should be unmasked if requested', function() {
let password = 'sUp3rS3kR_t!';
let result = maskPassword(password, 3);
expect(result).toBe('sUp*********');
});
test('all characters should be unmasked if requested', function() {
let password = '!t_Rk3Sr3pUs';
let result = maskPassword(password, 12);
expect(result).toBe(password);
});
});
Step by step
Solved in 3 steps with 1 images