Data Structure Visual Studio Code & JavaScript

Data Structure Visual Studio Code & JavaScript … Please help ?

<!doctype html>





// The sorting algorithms //


console.log("The sorting algorithms");

// 1. Implement ArrayList using the prototype.

// 2. Complete the createNonSortedRandomArray(size) below by returning an ArrayList with the numbers 1, 2, ..., size in random order. NOTE: there are multiple ways to achieve this.

function createNonSortedRandomArray(size) {

  // ...


// 3. Implement the Quick Sort algorithm and test your code with the function you wrote for (2).


// Searching algorithms //


console.log("Searching algorithms");

// 1. Implement the binary search algorithm and test your code.


// Project //



// The following set of steps come from an earlier homework.

// The following text is from the all the Amendments in the Bill of Rights.

var text = "Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances. A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed. No Soldier shall, in time of peace be quartered in any house, without the consent of the Owner, nor in time of war, but in a manner to be prescribed by law. The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no Warrants shall issue, but upon probable cause, supported by Oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. No person shall be held to answer for a capital, or otherwise infamous crime, unless on a presentment or indictment of a Grand Jury, except in cases arising in the land or naval forces, or in the Militia, when in actual service in time of War or public danger; nor shall any person be subject for the same offence to be twice put in jeopardy of life or limb; nor shall be compelled in any criminal case to be a witness against himself, nor be deprived of life, liberty, or property, without due process of law; nor shall private property be taken for public use, without just compensation. In all criminal prosecutions, the accused shall enjoy the right to a speedy and public trial, by an impartial jury of the State and district wherein the crime shall have been committed, which district shall have been previously ascertained by law, and to be informed of the nature and cause of the accusation; to be confronted with the witnesses against him; to have compulsory process for obtaining witnesses in his favor, and to have the Assistance of Counsel for his defence. In Suits at common law, where the value in controversy shall exceed twenty dollars, the right of trial by jury shall be preserved, and no fact tried by a jury, shall be otherwise re-examined in any Court of the United States, than according to the rules of the common law. Excessive bail shall not be required, nor excessive fines imposed, nor cruel and unusual punishments inflicted. The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people. The powers not delegated to the United States by the Constitution, nor prohibited by it to the States, are reserved to the States respectively, or to the people.";

// First we make the text lower case.

text = text.toLowerCase();

// Then we remove punctuation by using a regular expression.

text = text.replace(/[.,;]/g, "");

// And store the words into an array.

var textArray = text.split(" ");

// 1. Use sorting and searching to find out whether the word 'president' appears in the amendments. You should use the code you wrote above.

// 2. Use sorting and searching to find out whether the word 'state' appears in the amendments. You should use the code you wrote above.

// 3. Use sorting and searching to find out whether the word 'country' appears in the amendments. You should use the code you wrote above.




  See console!



Hello @Dode83 .

Not entirely sure what your question is.
The more information you give us, the more likely we are to be able to help.

Also the doctype should be written like this

<!DOCTYPE html>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

I don’t think I can provide more info I just copied everything to make it clear for all the experts but it is looking like I will never get help from you.

thanks anyway

You haven’t really told us what you need help with. You just pasted a lot of instructions and a few statements that don’t do much on their own. You just need to be more specific about what you need help with.

I agree with the other commenters that we just don’t have enough information. From what I can tell this is for some sort of homework assignment. But we have no clue what you are struggling with.

Like for example, what have you done with this first question.

What have you tried so far? What is giving you trouble?

There are alot of rockstar developers on the forum that would be happy to help you but you have to give us some more information to work with.

Hope that helps!

I tried to implement ArrayList as a prototype. I didn’t get any data in console…! This is my code…!

function ArrayList() {  

    var array = [];                                        // To create a data structure that stores items in an array. 

    this.prototype.insert = function(item) {              //The insert method to add elements in to data structure.    



  this.prototype.toString= function() {                             // To make all the array elements in only one string.   

  return array.join();  



  this.prototype.bubbleSort = function() {  

    var length = array.length;                     

    for (var i = 0; i < length; i++) {                   

  for (var j = 0; j < length - 1; j++ ) {              

  if (array[j] > array[j + 1]) {                        

    swap(array, j, j + 1);                              





  var swap = function(array, index1, index2) {  

    var aux = array[index1];  

    array[index1] = array[index2];  

    array[index2] = aux;


  function createNonSortedArray(size) {

   var array = new ArrayList();  

  for (var i = size; i > 0; i--) {    



    return array;


  var array = createNonSortedArray(10); 




Thanks for your reply… I have got this error
// Uncaught TypeError: Cannot set property ‘bubbleSort’ of undefined
at module-11-homework.html:25

  • Any advice please?

By taking a quick glance at the code, I think your use of var is probably giving you some weird results that you weren’t expecting. I would avoid using var and instead use let. Var has some scoping issues which is why it is not used anymore.

But also I would run the debugger on each of these functions and use the step over option to see step by step what is really going on with your code. And that will give you insight on if your functions are really doing what they are supposed to be doing.

Hope that helps!

:rose: :rose: :rose:
Thanks a lot

1 Like