This module provides a class for partitioning a string into three parts based on the last occurrence of a specified separator.
To use this module, you should have the "node-string-methods" npm package installed. You can install it using npm or yarn:
npm install node-string-methods
const RightPartition = require('node-string-methods/rightPartition');
// Create an instance of the RightPartition class with a string and separator
const str = 'apple,banana,cherry';
const separator = ',';
const partitioner = new RightPartition(str, separator);
// Execute the right partition operation
const result = partitioner.execute();
console.log(result);
// Output: ['apple,banana', ',', 'cherry']
str
(String): The input string that you want to partition.separator
(String): The separator string used to splitstr
into three parts based on the last occurrence.
Creates a new instance of the RightPartition
class with the provided input string and separator.
Partitions the input string into three parts: the part before the last occurrence of the separator, the separator itself, and the part after the separator.
- Returns: An array containing the three parts.
const RightPartition = require('node-string-methods/rightPartition');
const str = 'apple,banana,cherry';
const separator = ',';
const partitioner = new RightPartition(str, separator);
const result = partitioner.execute();
console.log(result);
// Output: ['apple,banana', ',', 'cherry']