Quick actions

cmd+k|ctrl+k

Navigation

Languages

id:pass

Snippet info

Language

JavaScript

Visibility

public

Author

fjrbgs

Created

2023-07-29T08:35:45.5445Z

Updated

2023-08-18T05:48:13.175704Z

const inputString = ``;
// Split the input string by newline characters
const lines = inputString.split('\n');

// Extract the first two parts before the pipe separator for each line and concatenate them with a colon separator
const convertedLines = lines.map((line) => {
  const parts = line.split(':');
  const firstTwoParts = parts.slice(0, 2);
  return `${firstTwoParts.join(':').trim()}`;
});

// Convert the array of lines back to a string, joining them with newline characters
const convertedString = convertedLines.join('\n');

console.log(convertedString);
INFO