Skip to content

Instantly share code, notes, and snippets.

@ashishb888
Created October 8, 2019 10:25
Show Gist options
  • Save ashishb888/bd9a9cd2c087adb732ef17626ac0b06b to your computer and use it in GitHub Desktop.
Save ashishb888/bd9a9cd2c087adb732ef17626ac0b06b to your computer and use it in GitHub Desktop.
Thoughtworks REST online test
var xmlhttp = new XMLHttpRequest();
var url = "https://http-hunt.thoughtworks-labs.net/challenge/input";
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
console.log("resp: ", resp);
var count = resp.text.length;
console.log("count: " + count);
var data = {
"wordCount": count
};
var xmlhttpPost = new XMLHttpRequest();
xmlhttpPost.open("POST", "https://http-hunt.thoughtworks-labs.net/challenge/output");
xmlhttpPost.setRequestHeader("userId", "yourId");
xmlhttpPost.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttpPost.send(JSON.stringify(data));
xmlhttpPost.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
console.log("resp: ", resp);
}
}
}
};
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("userId", "yourId");
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send();
var xmlhttp = new XMLHttpRequest();
var url = "https://http-hunt.thoughtworks-labs.net/challenge/input";
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
console.log("resp: ", resp);
var count = resp.text.split(" ").length;
console.log("count: " + count);
var data = {
"wordCount": count
};
var xmlhttpPost = new XMLHttpRequest();
xmlhttpPost.open("POST", "https://http-hunt.thoughtworks-labs.net/challenge/output");
xmlhttpPost.setRequestHeader("userId", "Ub3cQtSBf");
xmlhttpPost.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttpPost.send(JSON.stringify(data));
xmlhttpPost.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
console.log("resp: ", resp);
}
}
}
};
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("userId", "Ub3cQtSBf");
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send();
{
"stage": "2/4",
"statement": "Return the count of words in the paragraph.",
"instructions": "You can 'GET' the input from /challenge/input and output should be 'POST' json to /challenge/output. Important note: The time between request 'GET' input and 'POST' requests should not exceed 2 secs.",
"sampleInput": {
"input": {
"text": "Sunset is the time of day when our sky meets the outer space solar winds. There are blue, pink, and purple swirls, spinning and twisting, like clouds of balloons caught in a blender. The sun moves slowly to hide behind the line of horizon, while the moon races to take its place in prominence atop the night sky. People slow to a crawl, entranced, fully forgetting the deeds that still must be done. There is a coolness, a calmness, when the sun does set."
}
},
"sampleOutput": {
"output": {
"wordCount": 84
}
}
}
var xmlhttp = new XMLHttpRequest();
var url = "https://http-hunt.thoughtworks-labs.net/challenge/input";
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
console.log("resp: ", resp);
// var count = resp.text.match(/[\w|\)][.?!](\s|$)/g).length
var count = resp.text.match(/\b((?!=|\?|\.).)+(.)\b/g).length;
console.log("count: " + count);
var data = {
"sentenceCount": count
};
var xmlhttpPost = new XMLHttpRequest();
xmlhttpPost.open("POST", "https://http-hunt.thoughtworks-labs.net/challenge/output");
xmlhttpPost.setRequestHeader("userId", "Ub3cQtSBf");
xmlhttpPost.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttpPost.send(JSON.stringify(data));
xmlhttpPost.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
console.log("resp: ", resp);
}
}
}
};
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("userId", "Ub3cQtSBf");
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send();
{
"stage": "3/4",
"statement": "Return the number of sentences in a paragraph. Sentences will always be terminated by either fullstop (.) or question mark (?).There will be a space after each sentence, except last one",
"instructions": "You can 'GET' the input from /challenge/input and output should be 'POST' json to /challenge/output. Important note: The time between request 'GET' input and 'POST' requests should not exceed 2 secs.",
"sampleInput": {
"input": {
"text": "How often do you find yourself using an interrogation point in your everyday writing? What about an eroteme? You might be surprised to know that both of these appeared in the last two sentences. These terms might be unfamiliar, but you may know this punctuation mark by its more common name: the question mark. The question mark has a very simple function in writing—it indicates a question. If a sentence ends with a question mark, then it is asking a question, just as the name suggests."
}
},
"sampleOutput": {
"output": {
"sentenceCount": 6
}
}
}
var xmlhttp = new XMLHttpRequest();
var url = "https://http-hunt.thoughtworks-labs.net/challenge/input";
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
console.log("resp: ", resp);
// var count = resp.text.match(/[\w|\)][.?!](\s|$)/g).length
var data = {
"output": {
"a": 0,
"e": 0,
"i": 0,
"o": 0,
"u": 0
}
}
var a = resp.text.match(/a/g);
var e = resp.text.match(/e/g);
var i = resp.text.match(/i/g);
var o = resp.text.match(/o/g);
var u = resp.text.match(/u/g);
data.output.a = a === null ? 0 : a.length;
data.output.e = e === null ? 0 : e.length;
data.output.i = i === null ? 0 : i.length;
data.output.o = o === null ? 0 : o.length;
data.output.u = u === null ? 0 : u.length;
console.log("data: ", data);
var xmlhttpPost = new XMLHttpRequest();
xmlhttpPost.open("POST", "https://http-hunt.thoughtworks-labs.net/challenge/output");
xmlhttpPost.setRequestHeader("userId", "Ub3cQtSBf");
xmlhttpPost.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttpPost.send(JSON.stringify(data));
xmlhttpPost.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
console.log("resp: ", resp);
}
}
}
};
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("userId", "Ub3cQtSBf");
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send();
{
"stage": "4/4",
"statement": "Return the number of vowels in the paragraph. Ex. {a: 20, e: 32, i: 19, o: 2, u: 15}",
"instructions": "You can 'GET' the input from /challenge/input and output should be 'POST' json to /challenge/output. Important note: The time between request 'GET' input and 'POST' requests should not exceed 2 secs.",
"sampleInput": {
"input": {
"text": "Sunset is the time of day when our sky meets the outer space solar winds. There are blue, pink, and purple swirls, spinning and twisting, like clouds of balloons caught in a blender. The sun moves slowly to hide behind the line of horizon, while the moon races to take its place in prominence atop the night sky. People slow to a crawl, entranced, fully forgetting the deeds that still must be done. There is a coolness, a calmness, when the sun does set."
}
},
"sampleOutput": {
"output": {
"a": 20,
"e": 49,
"i": 23,
"o": 27,
"u": 11
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment