Output Transform

Learn how to use the output transformation feature.

“Output Transform” is as simple as it sounds. You can transform the console output based on your requirements. In the playground’s editor mode, just check the “Transform Output/Extract API Keys” checkbox:

widget

The following modal window opens up prompting the author to enter the output transformation code:

By default, the output transform stub function is as follows:

function outputTransform(stdout, stderr) {
  // TRANSFORM OUTPUT AS NEEDED
  const apiKeys = {};
  return { apiKeys, stdout, stderr };
}

The function takes in program output and errors as input. You may want to obtain API keys/tokens from the output or simply alter it. This functionality will come in handy for extracting API keys using the apiKeys object (as will be explained in the following lesson). The transformed output must be returned as an object.

The transformation code below just reverses the sequence of words in the output. So if the original code outputs Hello World, users will see World Hello in their execution output.

function outputTransform(stdout, stderr) {
  return { stdout: stdout.split(' ').reverse().join(' '), stderr };
}

You may try it in the playground below:

#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
}

“Output Transform” code can only be in JavaScript