function findPattern(strSrcTxt, strRegexPattern, strNotFoundReturnValue = "NA", intMatchGroup = 0) {
  let strFoundResults = strNotFoundReturnValue;
  
  const FoundMatch = strSrcTxt.match(strRegexPattern);
  
  if (FoundMatch && FoundMatch.length >= intMatchGroup) {
    strFoundResults = FoundMatch[intMatchGroup];
  }
  
  return strFoundResults;
}

const arrGPTResponse = [
  "Reason for contact: Plan change. Verification questions: The agent asked for the customer's name, date of birth, and home address, but the customer struggled to provide the correct information. Summary: The customer called to inquire about topping up for data, and the agent confirmed the current credit balance and last top-up date. However, the customer struggled to provide the correct personal information. The agent updated the customer's address and email, then offered an add-on data option and a new plan with unlimited data. The customer inquired about using WhatsApp and a better plan, and the agent explained the details of the new plan, including unlimited data for 28 days at 20 euros. The customer provided a voucher number for the top-up, and the call ended with the agent processing the voucher and promising to send a text message once the top-up is successful.",
  "Reason for contact: Plan and account assistance. Verification questions: The agent asked for the customer's name, date of birth, and email address, and the customer provided the correct information. Summary: The customer contacted Vodafone to address an issue with making calls and receiving a suspicious text message. The agent identified that the customer had exhausted their 100 any network national minutes and offered to add 100 any network national minutes for free for the next 28 days. The customer expressed confusion about the plan and data usage, and the agent suggested changing the plan to Chat Extra, which offers unlimited calls, texts, and 10GB of data. The customer agreed to the plan change and expressed gratitude for the assistance. The agent bid farewell, and the customer reciprocated before ending the call.",
  "Reason for contact: Credit not applied. Verification questions: The agent asked for the customer's date of birth and email to validate the account. Summary: The customer called on behalf of their mother to report that a top-up of 20 euros did not reflect in the account. The agent checked the account and confirmed the top-up and plan details. The customer's mother was advised to replace the outdated SIM card, and the agent explained that the credit was used to activate the plan, hence not reflected as a balance. The agent also mentioned that the outdated SIM card was causing issues with making calls and advised getting a replacement SIM card. The customer acknowledged and agreed to have the SIM card replaced.",
  "Reason for contact: Plan change. Verification questions: The agent asked for the customer's name, date of birth, and email address, and the customer passed the verification. Summary: The customer, Martina O'Connor, called on behalf of her husband to change to the Red Unlimited SIM Only plan for 35 euros per month, which includes unlimited calls, texts, and data. The agent confirmed the plan details, sent a one-time password for validation, and obtained authorization from the husband. The terms and conditions were read, and the order was placed to switch to the new plan. The customer provided an email address to receive the contract copy, and the agent confirmed the order placement. The agent also mentioned the option to upgrade the plan after six months and informed the customer that the order will be updated to the new plan soon. The call concluded with the customer expressing gratitude and bidding farewell.",
  "Reason for contact: Top-up issue. Verification questions: The agent asked for the customer's full name, date of birth, and phone number, and the customer provided the information correctly. Summary: The customer called to inquire about a top-up issue, stating that the plan was not activated despite topping up by 30 euros. The agent verified the details and acknowledged the issue, promising to rectify it within 24 to 48 hours. The customer also mentioned a broadband issue, but the agent explained that they were unable to activate the plan due to a system error and would escalate the issue for resolution. The agent assured the customer that the problem would be rectified and asked if there was anything else needed. The customer had no further queries and the call concluded with the agent assuring the customer that the issue would be resolved.",
  "Reason for contact: Plan migration. Verification questions: The agent asked for the customer's name, date of birth, and email address, and the customer provided the required information correctly. Summary: The customer called to migrate to a pay-as-you-go plan. The agent offered the Red Unlimited SIM Only plan for 35 euros per month for a 12-month contract, including unlimited calls and texts, 100 international minutes, 100 international texts, and unlimited data. The agent also mentioned the out-of-bundle charges and the 3% increase in pricing in January. The customer agreed to the plan and provided a one-time password for validation. The agent confirmed that the customer was not in any contract for the plan and proceeded with the order. The agent also offered insurance and a speed boost add-on, but the customer declined. The call was then transferred to the insurance team for cancellation. The agent informed the customer that a copy of the contract would be sent within 24 to 48 hours.",
  "Reason for contact: Account verification. Verification questions: The agent asked for the customer's full name, date of birth, and email address to validate the account. The customer provided the required information. Summary: The customer contacted the Vodafone call center to inquire about a new customer number and PIN for their account. The agent verified the customer's details and provided the customer number and PIN. The customer also inquired about their payment and was assured that the balance was clear. The agent advised against making an advanced payment and explained the billing cycle. The customer also sought assistance in removing an obsolete card and inquired about the direct debit payment date. The agent explained the payment date and assured the customer that their account was in good standing. The call concluded with the customer expressing gratitude and bidding farewell.",
  "Reason for contact: Technical issue with mobile app. Verification questions: The agent asked for the customer's name, date of birth, and email address, and the customer provided the required information. Summary: The customer called to report an issue with the mobile app, stating that they couldn't access it and were unable to log in. The agent confirmed the device details and suggested resetting the network settings, which the customer agreed to do. The agent assured the customer that they would call back after the reset. The customer agreed to the plan and mentioned that they would wait for the call back.",
  "Reason for contact: Billing inquiry. Verification questions: The agent asked for the customer's mobile number, full name, date of birth, and email address for validation, and the customer provided the required information correctly. Summary: The customer reported that their phone services were cut off, and the agent checked the account, finding an overdue balance of 88.95 euros for the bill period ending on the 29th of February. The customer mentioned making a payment on the 25th of March for the February bill, but the agent clarified that the overdue amount was for the March bill. The customer expressed frustration, and the agent offered to connect them to the collections team to make a payment and reactivate the services. The customer was dissatisfied and requested to speak to a manager, and the agent agreed to connect them to the collections team. The call ended with the customer expressing frustration. No mention of a follow-up call or the duration for the call listening by the agent's supervisor.",
  "Reason for contact: Voucher redemption issue. Verification questions: The agent asked for the customer's name, date of birth, and email, and the customer provided the required information correctly. Summary: The customer called to redeem two vouchers for topping up but encountered issues with the redemption process. The agent verified the customer's details and attempted to redeem the vouchers, but encountered technical glitches on the Vodafone gateway. The agent apologized and assured the customer that the issue had been escalated, and it was a widespread problem affecting multiple customers. The customer was informed that the issue would be resolved within 24 hours, and the agent advised the customer to try again later. The customer expressed frustration but understood the situation, and the call concluded with the agent apologizing for the inconvenience. No mention of the duration for the agent's supervisor to listen to the call.",
  "Reason for contact: TV Box features and multi-room setup. Verification questions: The agent asked for the customer's name, another name on the account, date of birth, email, and mail code. The customer provided the required information correctly. Summary: The customer called to inquire about the TV Box features, expressing dissatisfaction with the inability to record certain channels on the new TV Box. The agent explained that the rights for recording certain channels were not available on the new box. The customer also discussed the multi-room setup and expressed frustration at the additional cost for a new box. The agent explained the charges for the new box and the monthly rental cost. The customer expressed disappointment and mentioned considering switching to another provider due to the perceived decline in service quality. The agent informed the customer about the termination process and associated fees. The customer expressed intent to terminate the contract and explore other options. The call concluded with the customer expressing dissatisfaction and the agent expressing gratitude.",
  "Reason for contact: Setting up automatic top-up. Verification questions: Name, date of birth, and email were requested and successfully provided by the customer. Summary: The customer called to set up an automatic top-up but encountered difficulty entering the CVV number in the app. The agent guided the customer to log in through the website and provided assistance in navigating to the top-up option. The customer was able to set up the top-up and received confirmation. The agent also requested the customer to provide feedback in a survey after the call."
];

const strReasonRegexPattern = /^\s*Reason\sfor\scontact:((.|\n)*)Verification\squestions:/i;
const intReasonMatchGroup = 1;
const strInvalidResponseReason = "Reason not found!";

for (const i in arrGPTResponse){
  strResponse = arrGPTResponse[i];
  
  let result = findPattern(strResponse, strReasonRegexPattern, strInvalidResponseReason, intReasonMatchGroup);
  console.log(result.trim());
}

 

Javascript Online Compiler

Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.

About Javascript

Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.

Key Features

  • Open-source
  • Just-in-time compiled language
  • Embedded along with HTML and makes web pages alive
  • Originally named as LiveScript.
  • Executable in both browser and server which has Javascript engines like V8(chrome), SpiderMonkey(Firefox) etc.

Syntax help

STDIN Example

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', function(line){
    console.log("Hello, " + line);
});

variable declaration

KeywordDescriptionScope
varVar is used to declare variables(old way of declaring variables)Function or global scope
letlet is also used to declare variables(new way)Global or block Scope
constconst is used to declare const values. Once the value is assigned, it can not be modifiedGlobal or block Scope

Backtick Strings

Interpolation

let greetings = `Hello ${name}`

Multi line Strings

const msg = `
hello
world!
`

Arrays

An array is a collection of items or values.

Syntax:

let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);

Example:

let mobiles = ["iPhone", "Samsung", "Pixel"];

// accessing an array
console.log(mobiles[0]);

// changing an array element
mobiles[3] = "Nokia";

Arrow functions

Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.

Syntax:

() => expression

Example:

const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
                                    .map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);

De-structuring

Arrays

let [firstName, lastName] = ['Foo', 'Bar']

Objects

let {firstName, lastName} = {
  firstName: 'Foo',
  lastName: 'Bar'
}

rest(...) operator

 const {
    title,
    firstName,
    lastName,
    ...rest
  } = record;

Spread(...) operator

//Object spread
const post = {
  ...options,
  type: "new"
}
//array spread
const users = [
  ...adminUsers,
  ...normalUsers
]

Functions

function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
  console.log(`Hello ${name}!`);
}
 
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar

Loops

1. If:

IF is used to execute a block of code based on a condition.

Syntax

if(condition){
    // code
}

2. If-Else:

Else part is used to execute the block of code when the condition fails.

Syntax

if(condition){
    // code
} else {
    // code
}

3. Switch:

Switch is used to replace nested If-Else statements.

Syntax

switch(condition){
    case 'value1' :
        //code
        [break;]
    case 'value2' :
        //code
        [break;]
    .......
    default :
        //code
        [break;]
}

4. For

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
//code  
} 

5. While

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
  // code 
}  

6. Do-While

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
  // code 
} while (condition); 

Classes

ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.

Syntax:

class className {
  constructor() { ... } //Mandatory Class method
  method1() { ... }
  method2() { ... }
  ...
}

Example:

class Mobile {
  constructor(model) {
    this.name = model;
  }
}

mbl = new Mobile("iPhone");