Get before substring

Inputs

  • MyString
  • Substring

Outputs

  • before substring

Neuron type

Best algorithm has been found - locked

Patterns

Pattern Input Output
1.
MyString: abcd
Substring: cd
before substring: ab
2.
MyString: 123456
Substring: 6
before substring: 12345

Applicable neurons

  • 0
  • Position
  • Substring (startPosition, endPosition)

Algorithm

Test

Code made by AI:
/**
 * Position: Search position substring of string
 *
 * @param x1 MyString
 * @param x2 FindMe
 * @return {Array}
 */
function neuron523(x1, x2)
{
return [x1.toString().indexOf(x2.toString())];
}

/**
 * 0: 
 *
 * @return {Array}
 */
function neuron500()
{
return [0];
}

/**
 * Substring (startPosition, endPosition): Get substring from string - from position - to pos
 *
 * @param x1 MyString
 * @param x2 start position
 * @param x3 end position
 * @return {Array}
 */
function neuron525(x1, x2, x3)
{
return[x1.toString().substring(x2, x3)];
}

/**
 * Get before substring: 
 * 
 * @param x1 MyString
 * @param x2 Substring
 * @return {Array}
 */
function neuron532(x1, x2)
{
  var outputs = [];
  outputs[0] = x1;
  outputs[1] = x2;

  arr = neuron523(outputs[0], outputs[1]);
  outputs[2] = arr[0];

  arr = neuron500();
  outputs[3] = arr[0];

  arr = neuron525(outputs[0], outputs[2], outputs[3]);
  outputs[4] = arr[0];

  return[outputs[4]];
}


Code made by AI:

Create your family tree for free