Skip to content
Advertisement

Tag: algorithm

Longest palindrome in a string

I wrote the following function to find the longest palindrome in a string. It works fine but it won’t work for words like “noon” or “redder”. I fiddled around and changed the first line in the for loop from: to and now it works, but I’m not clear on why. My intuition is that if you are checking an odd-length

Javascript Coin changing / Change making algorithm

So I’ve been trying to create a program in Javascript/jQuery that splits an amount of money into the smallest amount of dollar bills. So far the program only works with one bill, and I’m not too sure how to implement the rest and need a push in the right direction here. If I run this with money = 89; it

How to calculate average time

how to calculate average time with 11:59:00 PM and 12:00:00 AM so that it can be 11:59:30 PM. currently this code is giving me 11:59:30 AM Answer This is a function for if you are looking for an average time given a set of times, regardless of date, given a 24 hr period. It works for 12am – 12pm but

Javascript Array.sort implementation?

Which algorithm does the JavaScript Array#sort() function use? I understand that it can take all manner of arguments and functions to perform different kinds of sorts, I’m simply interested in which algorithm the vanilla sort uses. Answer I’ve just had a look at the WebKit (Chrome, Safari …) source. Depending on the type of array, different sort methods are used:

Advertisement