Question: Write a function in JAVASCRIPT ES 5 ( PLEASE I NEED IT URGENTLY IN 3 0 MINS ) function solution ( S , T )

Write a function in JAVASCRIPT ES5(PLEASE I NEED IT URGENTLY IN 30 MINS)
function solution(S,T);
that, given two string S and T consisting of N and M characters, respectively, determines whether string T can be obtained from the string S by at most one simple operation from the set specified below. The function should return a string:
"INSERT c" if string T can be obtained from string S by inserting a single character "c" at the beginning of the string;
"REMOVE c" if string T can be obtained from string S by deleting a single character "c" at the beginning of the string;
"SWAP c d" if string T can be obtained from string S by swapping two adjacent characters "c" and "d"(these characters should be distinct and in the same order as in string S; exactly one swap is performed).
"EQUAL" if no operation is needed (strings T and S are equal);
"IMPOSSIBLE" if none of the above works.
Note that by characters "c" and "d" from the operations above, we mean any English alphabet lowercase letters.
For example:
Given S = "gain" and T = "again", the function should return "INSERT a"
Given S = "parks" and T = "park", the function should return "REMOVE s"
Given S = "form" and T = "from", the function should return "SWAP o r"
Given S ="o" and T = "odd", the function should return "IMPOSSIBLE"
Given S = "fift" and T = "fifth", the function should return "IMPOSSIBLE"
Assume that: N and M are integers within the range [1,100] and strings S and T are made only of lowercase letters (a-z).
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

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 Accounting Questions!