Get the last XY characters

Description

Substring from {endOfString - x} to {endOfString}

Inputs

  • string
  • x

Outputs

  • last x characters

Neuron type

Best algorithm has been found - locked

Patterns

Pattern Input Output
1.
string: abcd
x: 2
last x characters: cd
2.
string: 12345
x: 5
last x characters: 12345
3.
string: abc
x: 1
last x characters: c
4.
string: 00000000001
x: 3
last x characters: 001

Applicable neurons

  • Minus (x - y)
  • Length of string
  • Substring (from position to end)
  • Volume Of a Cylinder
  • NOT
  • Rounding to whole tenths of something
  • character l
  • Price without VAT
  • character ≤
  • 12

Algorithm

Test

Code made by AI:
/**
 * Length of string: 
 *
 * @param x1 String
 * @return {Array}
 */
function neuron528(x1)
{
return[x1.toString().length];
}

/**
 * Minus (x - y): 
 *
 * @param x1 Number X
 * @param x2 Number Y
 * @return {Array}
 */
function neuron2(x1, x2)
{
math.config({number: 'BigNumber', precision: 64}); return [math.eval(Number(x1) + '-'+Number(x2)).toString()];
}

/**
 * Length of string: 
 *
 * @param x1 String
 * @return {Array}
 */
function neuron528(x1)
{
return[x1.toString().length];
}

/**
 * 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)];
}

/**
 * Substring (from position to end): 
 * 
 * @param x1 MyString
 * @param x2 start position
 * @return {Array}
 */
function neuron529(x1, x2)
{
  var outputs = [];
  outputs[0] = x1;
  outputs[1] = x2;

  arr = neuron528(outputs[0]);
  outputs[2] = arr[0];

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

  return[outputs[3]];
}


/**
 * Get the last XY characters: Substring from {endOfString - x} to {endOfString}
 * 
 * @param x1 string
 * @param x2 x
 * @return {Array}
 */
function neuron727(x1, x2)
{
  var outputs = [];
  outputs[0] = x1;
  outputs[1] = x2;

  arr = neuron528(outputs[0]);
  outputs[2] = arr[0];

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

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

  return[outputs[4]];
}


Code made by AI:

Create your family tree for free