index.js 459 B

12345678910111213141516171819202122
  1. 'use strict';
  2. module.exports = (string, separator) => {
  3. if (!(typeof string === 'string' && typeof separator === 'string')) {
  4. throw new TypeError('Expected the arguments to be of type `string`');
  5. }
  6. if (separator === '') {
  7. return [string];
  8. }
  9. const separatorIndex = string.indexOf(separator);
  10. if (separatorIndex === -1) {
  11. return [string];
  12. }
  13. return [
  14. string.slice(0, separatorIndex),
  15. string.slice(separatorIndex + separator.length)
  16. ];
  17. };