//Main function
function main() {
var line = "";
var allLines = [];
while ((line = readLine()) != "") {
allLines.push(line);
}
print(allLines.sort());
var sortedLines = (insertionSort_GStore(sortAlpha(allLines)));
print("\n final list sorted first alphabetically and then by word length: ");
for (var i = 0; i < sortedLines.length; i++) {
print(sortedLines[i]);
}
}
function sortAlpha(list) {
var listSorted = list.sort();
print("Alphabetically sorted list: ");
for (var g = 0; g < listSorted.length; g++) {
print(listSorted[g]);
}
print("\n");
return (listSorted);
}
function insertionSort_GStore(list) {
var output = list.slice(0);
print("alphabetically sorted list, now passed into the Insertion Sort function and sliced: " + output);
for (var i = 1; i < output.length; i++) {
for (var k = i; k > 0 && wordLength(output[k]) < wordLength(output[k - 1]); k--) {
var temp = output[k];
output[k] = output[k - 1];
output[k - 1] = temp;
}
}
return output;
}
function wordLength(word) {
return (word.length);
}
function func(a, b) {
if (b == 0) {
return a;
}
return (func(b, a % b));
}
function multipleVision(string, n) {
var output = "";
for (var i = 0; i < n; i++) {
output += string;
}
return output;
}
function halver(n) {
return n / 2;
}
function doubleVision(string) {
return string + string;
}
function calculator() {
var zoeRecord = 1.21;
var coolLamp = 2.33;
var shorts = 0.95;
var input;
var total = 0;
while ((input = readLine()) != "") {
var arr = input.split(" ");
if (arr[0] == "add") {
if (arr[1] == "record") {
total += zoeRecord;
print("record - $" + zoeRecord);
} else if (arr[1] == "lamp") {
total += coolLamp;
print("lamp - $" + coolLamp);
} else {
total += shorts;
print("shorts - $" + shorts);
}
} else {
if (arr[1] == "record") {
total -=...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.