Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago