Skip to main content

Command Palette

Search for a command to run...

The Charlottetown Murders: JS Methods to the Rescue

Solving a Murder Mystery While Learning JavaScript Methods

Updated
6 min read
The Charlottetown Murders: JS Methods to the Rescue

Chapter 1 - The murders

On February 1st, 2025, a series of murders wreaked havoc on the streets of Charlottetown. The residents of this small town are gripped by panic and fear, worried that one night, their families might become part of the news for tragic reasons, and they may never see the light of day again. The Charlottetown police department is awestruck, with many officers resigning due to threatening messages from unknown senders about the abduction of their families. Everyone in the town, including law enforcement, is in danger. The Head of the Charlottetown Police Department, Mr. Clarke, has imposed a lockdown, preventing anyone from entering or leaving the town until those responsible for these atrocities are found. Clarke has reached out to Inspector Daya, a renowned detective, to unravel this inexplicable series of events that have paralyzed the entire town. The responsibility to protect 5,000 innocent civilians now rests in his hands.

Chapter 2 - The Hunt Begins

Daya receives an email from Clarke containing the details of the occurrences. Click below to see the message.

Message from Clarke
"The details of the case are as follows: we know that the murders happened in the north, south and in the heart of the town, all highly populated areas. The current death toll as of February 3rd stands at 45. Now, we don't know for sure that these murders were orchestrated by a gang or an individual because all the murders are so identical that it looks like a single person did them. Since it's almost impossible for a single person to kill at three different places at the same time, we estimate that the group includes at least three people. The murderers brutally murdered exactly 15 people total at all three locations combined every night since February 1st, using knives. A peculiar signature of the murders is that they leave a note near the bodies saying the phrase 'HADRAN 07'. Feel free to contact the local police department for a detailed suspect list."

Armed with this information, Daya set out to uncover the truth behind the bloodshed.

Chapter 3 - The Investigation

The local police gave a list of 10 men who are suspects in the downtown murder case.

downtownPoliceSuspects = ["Liam", "Noah", "Oliver", "Elijah", "James", "William", "Benjamin", "Lucas", "Henry", "Harry"]

Daya begins to do individual investigations from the town's downtown region, hoping to get some witnesses for the crime. He goes around the murder block and finds out from two eyewitnesses that they say with certainty that the murderer looked like a man who was 6 ft in height and in his early 30s. Using police records, he obtained two lists—one for height and another for age:

suspectsHeight = [5.55, 5.04, 6.15, 5.53, 6.51, 6.34, 6.16, 6.42, 5.27, 6.0,]
suspectsAge = [14, 13, 15, 21, 11, 25, 15, 9, 22, 15]

Sort()

Sorting the heights of the suspects:

suspectsHeightSorted = suspectsHeight.sort();
// Output: Array [5.04, 5.27, 5.53, 5.55, 6.0, 6.15, 6.16, 6.34, 6.42, 6.51];

Shift()

He then removed all suspects under 6 feet using the shift() method:

suspectsHeightSorted.shift();
suspectsHeightSorted.shift();
suspectsHeightSorted.shift();
suspectsHeightSorted.shift();

suspectsHeightSorted = [6.0, 6.15, 6.16, 6.34, 6.42, 6.51];

Therefore, the updated list contains:

mySuspects = ["Harry", "Oliver", "Benjamin", "William", "Lucas", "James"]
mySuspectsAge = [15, 15, 15, 25, 9, 14]

Shockingly, Daya finds a major flaw in the age list. The majority of the people on the list were CHILDREN!!! "How is it possible?" exclaimed Daya. However, just to be absolutely certain, he decided to use every() function to check if all suspects were under 30:

every()

isBelow30 = (mySuspects ) => mySuspects < 30;
console.log(mySuspects.every(isBelow30));
//Output: true

And not to his surprise, yes, indeed, the boolean output was True, confirming the inconsistency.

Daya decided to contact the police department to address this issue. To his disappointment, he was told that the actual age of all the people was twice the age mentioned in the suspectsAge list. They explained that their record book was really old since it's a tiny town, and the department was careless with record handling.

map()

Anyhow, Daya decides to continue his pursuit of finding the killers using the map() method.

mySuspectsAgeUpdated = mySuspectsAge.map((x) => x * 2)
console.log(mySuspectsAgeUpdated);
//Output: Array [30, 30, 30, 50, 18, 28]

Now, with the updated array, Daya has decided to remove everybody who is not thirty years of age or above.

pop()

mySuspectsAgeUpdated.pop();
mySuspectsAgeUpdated.pop();
mySuspectsAgeUpdated.pop();

console.log(mySuspectsAgeUpdated);
//Output: Array[30, 30, 30]

mySuspectsDowntown = ["Harry", "Benjamin", "Oliver"]

During a conversation with a police officer that he made friends with, Daya came to know that James was a notorious criminal who had been to jail a couple of times and had a really bad temper problem. Also, his age being close to 30, Daya decided to put James back on the list.

push()

console.log(mySuspectsDowntown.push("James"));
//Output: Array ["Harry", "Benjamin", "Oliver", "James"]

It all boiled down to these four men for the downtown area. Daya decided not to contact the local police due to the lack of any hard evidence yet.

Chapter 3: Momentum in the case

Daya worked overnight, went to both crime locations in the north and south, and finalized a list of all the suspects for the crime.

mySuspectsNorthSide = ["Daniel", "Matthew", "Drake"];
mySuspectsSouthSide = ["Ethan", "Alexander", "Samuel", "Nathan", "Andrew"];

concat()

To streamline his work, Daya decided to concatenate the list using the concat() method and sort them in alphabetical order:

suspects = mySuspectsDowntown.concat(mySuspectsNorthSide, mySuspectsSouthSide);
suspects = ["Harry", "Benjamin", "Oliver". "Daniel", "Matthew", "Drake", "Ethan", "Alexander", "Samuel", "Nathan", "Andrew"];

suspectsSorted = suspects.sort();
suspectsSorted = ["Alexander", "Andrew", "Benjamin", "Daniel", "Drake", "Ethan", "Harry", "James", "Matthew", "Nathan", "Oliver", "Samuel"]

Reverse()

To look at the list from a different perspective, Daya decides to reverse the list:

console.log(suspectsSorted.reverse());
// Array ["Samuel", "Oliver", "Nathan", "Matthew", "James", "Harry", "Ethan", "Drake", "Daniel", "Benjamin", "Andrew", "Alexander"]

While analyzing, something strange popped out. Daya recalled the gang members named themselves 'HADRAN 07'; “What if”, he thought, “ the suspect’s name was an acronym encapsulated the initials of the gang members?”. To test his theory, he decides to make a list only of the suspects whose initial names resemble the Signatures.

Splice()

console.log(suspectsSorted.splice(5,0));
//Output: Array ["Harry", "Ethan", "Drake", "Daniel", "Benjamin", "Andrew", "Alexander"]

console.log(suspectsSorted.splice(1,1));
//Output: Array ["Harry", "Drake", "Daniel", "Benjamin", "Andrew", "Alexander"]

console.log(suspectsSorted.splice(2,2));
//Output: Array ["Harry", "Drake", "Andrew", "Alexander"]

console.log(suspectsSorted.pop());
//Output: Array ["Harry", "Drake", "Andrew"]

Chapter 4: Finally!!!

Join()

suspectsSorted.join("-");
//Output: Array["Harry-Drake-Andrew"]

"Hmm", says Inspector Daya, " So HA for Harry, DR for Drake and AN for Andrew". Giving a confused look, he says, "Alright, if my absurd theory about the name initial is correct, why these three guys?…what could possibly be the reason for them to commit such murders?" He requests all the details about these three individuals history from the local police.

Scavenging for a common link between the three, He discovered that in 2007, these three men had escaped prison and committed a series of armed robberies. The trio, now known as ‘HADRAN 07,’ had returned to terrorize Charlottetown.

Realizing he had cracked the case, Daya immediately relayed his findings to the authorities. With solid evidence in hand, the police arrested Harry, Drake, and Andrew, bringing an end to the reign of terror.

Through meticulous analysis, logical deduction, and advanced problem-solving skills, Inspector Daya successfully unmasked the murderers. His determination not only solved the case but also restored peace to Charlottetown.

Beyond a thrilling detective story, this case serves as an engaging way to understand JavaScript instance methods like sort(), shift(), map(), every(), splice(), pop(), push(), reverse(), join() and concat(). Inspector Daya's journey exemplifies how critical thinking and programming can work hand in hand to solve even the most perplexing mysteries.

Justice has prevailed. The streets of Charlottetown are safe once more.