var textInput = document.getElementById("textInput");
var btnMap = document.getElementById("btnMap");
var btnApply = document.getElementById("btnApply");
var btnBind = document.getElementById("btnBind");
var btnCall = document.getElementById("btnCall");
var output = document.getElementById("output");
//change str to array of char
var strToArr = function(str) {
var arr = [];
var i, len;
len = str.length;
for (i=0; i<len; i++) {
arr.push(str.charAt(i));
}
return arr;
};
//call example (display function)
var showOutputA = function(outputText) {
this.innerHTML = outputText;
}
//apply example (display function advanced)
var showOutputB = function(text1, text2) {
var outputText = '';
if (text1 === "N") {
outputText += "The following characters are not numbers:<br>";
} else {
outputText += text1;
}
if (text2.constructor === Array) {
outputText += text2.join(',');
} else {
outputText += text2;
}
this.innerHTML = outputText;
};
//map function (filter all characters that are not numberic)
var filterChar = function(char) {
if (isNaN(char)) {
return char;
}
};
btnMap.onclick = function() {
var text = textInput.value;
var chars = strToArr(text);
var nonNum = chars.map(filterChar);
showOutputB.apply(output, ["Non numbers: <br>", nonNum]);
};
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.