Tagged Questions
6
votes
1answer
154 views
Converting any PHP function toString() like in JS
In JavaScript, any function is basically an object on which you can call (function(){}).toString() to get it's underlying code as a string.
I'm working on a ...
6
votes
1answer
67 views
Text Analysis web page
For a homework assignment, I made a web page that has a text area. The user inputs some text, hits the analyse button, and the output is supposed to be a list of the frequency of words of a given ...
2
votes
1answer
73 views
Easiest way to remove extra spaces from user input?
What I want to do:
Take user input strings and add them together with proper spacing.
HTML:
...
3
votes
1answer
69 views
Breaking after one of several string replaces occur
I have a script that matches a string against ~20 different regexs for the purpose of changing it. They are ordered and formed that the string will only ever match against one. How can I avoid ...
3
votes
2answers
114 views
Calculate all possible combinations of an array of arrays or strings
I'm using code adapted from this Stack Overflow question to calculate all possible combinations from an array, which may contains strings.
For example:
...
6
votes
1answer
164 views
BBCode to HTML converter using functional programming
I was inspired to write a BBCode to HTML converter as I'm currently learning functional programming. I wanted achieve functional cohesion. jsFiddle
I'd like feedback on:
structuring of the code. ...
6
votes
1answer
119 views
Balanced parentheses
Given an expression string exp, write a program to examine whether the
pairs and the orders of
"{","}","(",")","[","]"
are correct in exp.
For ...
1
vote
1answer
217 views
Milliseconds to Time string & Time string to Milliseconds
Fast Time conversion
I'm trying to write a very fast time-to-string and string-to-time function.
I noticed that on low CPU mobile devices this function has, even if minimal, impact on the ...
11
votes
7answers
1k views
Write a function to find the first non-repeated character in a string
Here is a practice question I am solving:
Write a function to find the first non-repeated character in a string.
For instance, the first non-repeated character in 'total' is 'o' and
the first ...
5
votes
1answer
72 views
Coderbyte: String Reduction
From Coderbyte:
Have the function StringReduction(str) take the str parameter being
passed and return the smallest number you can get through the
following reduction method. The method is: ...
3
votes
2answers
141 views
Counting the words in a textarea
I've two working ways to do so, but which one should I use?
Common part: var textarea = document.getElementById("textarea");
First way:
...
1
vote
2answers
76 views
Reducing cyclomatic complexity in a simple string concatenation
I have written the following function that takes an address object and builds a string using the object properties. It will later be used to display a tooltip
...
7
votes
1answer
311 views
Find the word in a string that has the most repeated characters
The problem: I want to find the word in a string that has the most repeats of a single letter, each letter is independent. Does not need to be consecutive.
Currently I am jumping each character and ...
5
votes
1answer
64 views
Edit string to concatenate word numbers in javascript
I would like to replace the string "The quick brown fox jumps over the lazy dog" with the string "The1 quick2 brown3 fox4 jumps5 over6 the7 lazy8 dog9".
Is there an cleaner, more elegant, sexier way?
...
7
votes
1answer
120 views
l33t Speak translator
Please review the code quality of this l33t Speak translator. Improvement suggestions are welcome. Here it is - http://jsbin.com/IHoFuQE/1
...
6
votes
3answers
284 views
Coderbyte SimpleSymbols challenge in Javascript
I am working on a CoderByte problem in JavaScript. I have solved the problem below. Although I am trying to figure out if there is an easier way to do it? I am guessing RegEx will come up, although I ...
7
votes
2answers
113 views
Tabulate text with JavaScript
Pretty printer in ABAP does not take care of all my aligning need, so I wrote a small JS script that tabulates/aligns with a custom string. It contains HTML, CSS and script in 1 file because this is a ...
6
votes
3answers
1k views
Count byte length of string
I am looking for some guidance and optimization pointers for my custom JavaScript function which counts the bytes in a string rather than just chars. The website uses UTF-8 and I am looking to ...
-3
votes
2answers
79 views
Replacing parenthesis in code [closed]
I am trying to write a string or integer formula which will look for code between parentheses.
My logic is this:
Search for the first parentheses, find the last parentheses, and return everything in ...
1
vote
3answers
111 views
How to simplify this matrix transposition of a string or make it more readable?
Per a Reddit Daily Programming Challenge, I am performing a matrix transposition on a string using JavaScript.
Example input: 'The quick brown fox jumped over the lazy dog'
Output:
...
1
vote
3answers
164 views
Testing distance between characters in a string
Here is another challenge from Coderbyte. I found this one challenging, although not quite as much as the previous two I've posted. Based on the feedback I received on my earlier posts, I structured ...
2
votes
2answers
75 views
Encoding strings using periodic table abbreviations
I took a JavaScript challenge to finish a task related to logo of "Breaking Bad" where letters in your first name and last name are spotted with elements of periodic table and its respective atomic ...
4
votes
2answers
4k views
Trim certain characters from a string in JavaScript
I want to remove not only spaces, but certain characters, as well from the beginning or end of a JavaScript string.
...
1
vote
1answer
219 views
Implementation of String object as an exercise
I am reading "Object-Oriented JavaScript" by Stoyan Stefanov to learn JavaScript and in the end of the chapter named "Objects", there's an exercise that asks you to implement your own ...
3
votes
1answer
130 views
String processing in JavaScript
We have a lot of phone numbers that contain dashes and start with a zero which are from another country.
I am trying to strip the dashes and the one leading zero and select the country code from a ...
3
votes
1answer
2k views
Faster JavaScript fuzzy string matching function?
I'm using the following function to fuzzy match strings:
...
0
votes
2answers
241 views
Elegant function to “increase” a JavaScript string - for example, turning “aac” into “aad”
I'm writing a function to increase a string so, for example, "aac" becomes "aad" and "aaz" becomes "aba". The result is horribly inelegant, I can't get it simple enough and I feel I'm missing ...
2
votes
1answer
164 views
Implement numbering scheme like A,B,C… AA,AB,… AAA…, similar to converting a number to radix26
I want to implement numbering scheme like Microsoft Word uses for numbering.
first one gets = A,next is B, next is C, .... then AA, then AB,....and so on.
as shown below
...
4
votes
2answers
3k views
3
votes
3answers
291 views
Calculating user birth information
Can you please check if I've written the code correctly?
The task was:
Calculate the user's month of birth as a a number, where January = 0 through to December = 11.
Take the string entered
Get ...
0
votes
2answers
45 views
Javascript Repeating Method… Better way to do this?
I'm sure there's a better way to approach the following. I'm writing a plugin. Users can enter settings in the following foramt: setting: "object1setting -> object2setting", It's done this way to ...
2
votes
1answer
407 views
How can I improve performance for my JavaScript table class?
I've written a JavaScript table class to make it easy to display tabular data and allow the user to sort the data by clicking on the table headers.
However, when there are hundreds of rows, ...
5
votes
2answers
277 views
2
votes
2answers
148 views
Searching for a string in a web page
I have written the below code to search for a string in a web page. This is working fine but I need suggestions on improving this code to start using this. This is written to work under IE.
...
3
votes
1answer
1k views
Outputting a countdown in a div
I got this code working with the jQuery Countdown Plugin to take a string input and output a countdown in a div. Is there a better way of implementing this?
JSFiddler
HTML
...
2
votes
3answers
1k views
String.IsNullOrWhiteSpace in JavaScript
I am aware of it being frowned upon to do something like write C# in JavaScript. (See Write Cobol in any language if you don't know what I'm talking about.)
But as a judgement call I think we could ...
3
votes
3answers
248 views
Improving the code to turn a string into an array of numbers?
I have a string of numbers, like "31654918562314", and I want to convert it into an array of integers. The code I've written is:
...
0
votes
1answer
140 views
Making an encoding function faster
I currently have this encoding function which simply subtracts one from each character code:
...
11
votes
2answers
16k views
Pack and unpack bytes to strings
I need to write a function that "packs" an array of bytes (integers between 0 and 255) into a string. I also need to be able to perform the reverse operation, to get my byte array from the string that ...
10
votes
1answer
430 views
String interpolation library
I was bored over the last couple of days and wrote up a string interpolation library for JavaScript.
I'm very pleased with its functionality, it passes it 79 tests cross browser and the comments and ...