Question: const { snake } = require('./solutions'); describe('Problem 1 - snake() function', function () { test('returns string unmodified if it needs no changes', function () {

const { snake } = require('./solutions');

describe('Problem 1 - snake() function', function () {

test('returns string unmodified if it needs no changes', function () {

let result = snake('abc');

expect(result).toBe('abc');

});

test('returns string with leading whitespace removed', function () {

let result = snake(' abc');

expect(result).toBe('abc');

});

test('returns string with trailing whitespace removed', function () {

let result = snake('abc ');

expect(result).toBe('abc');

});

test('returns string with all lowercase letters', function () {

let result = snake('AbC');

expect(result).toBe('abc');

});

test('returns string with internal spaces removed', function () {

let result = snake('A B C');

expect(result).toBe('a_b_c');

});

test('returns string with internal tabs removed', function () {

let result = snake('A\tB\tC');

expect(result).toBe('a_b_c');

});

test('returns string with mixed internal tabs and spaces removed', function () {

let result = snake('A B\t\t C');

expect(result).toBe('a_b_c');

});

test('returns string with periods removed', function () {

let result = snake('A.B..............................C');

expect(result).toBe('a_b_c');

});

test('returns string with periods, tabs, and spaces removed', function () {

let result = snake(' A. b. . . . . . . \t\t\t ....\t. . . . . ......c.. ....d ');

expect(result).toBe('a_b_c_d');

});

});

THIS FILE IS PROBLEM-1 FILE

/*******************************************************************************

* Problem 1: replace all internal whitespace in a string value with underscore

* ('_'), and makes it lowercase.

*

* We want to be able to convert a string to Lower Snake Case style, so that all

* leading/trailing whitespace is removed, and any internal spaces, tabs, or dots,

* are converted to '_' and all letters are lower cased.

*

* The snake() function should work like this:

*

* snake('abc') --> returns 'abc'

* snake(' ABC ') --> returns 'abc'

* snake('ABC') --> returns 'abc'

* snake('A BC') --> returns 'a_bc'

* snake(' A bC ') --> returns 'a-bc'

* snake('A BC') --> returns 'a_bc'

* snake('A.BC') --> returns 'a_bc'

* snake(' A.. B C ') --> returns 'a_b_c'

*

* @param {string} value - a string to be converted

* @return {string}

******************************************************************************/

function snake(value) {

// Replace this comment with your code...

}

aND THIS IS SOLUTION.JS FILE. PLEASE PUT SOLUTION INSIDE THIS FILE,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!