Sorting Strings Alphabetically

This is for the Create PT.

I have a student trying to sort strings alphabetically. The aim of his app is to organize states by their letter, as in, when you choose, “A,” all states beginning with “A” are output.

The student has tried several things to no avail. This is my first year teaching this and I feel stumped. I have looked at Javascript solutions but still don’t know how it translates to Code.org.

I don’t have the full list of what he’s tried, but just getting some suggestions on resolving this would be a huge help.

Hi @jkralicek,

Unfortunately, if a student is working on the Create PT, then you and we cannot help them - even to debug code. This is a violation of the academic integrity of the exam so your best solution for “helping” the student is as follows:

  • suggest they break down the problem in to sub-problems
  • encourage them to look at the documentation that exists (code.org or elsewhere with regards to javascript)
  • suggest they go back to lessons you’ve already done this year that solve a similar problem and see how the problem was solved in these cases

I know its frustrating to watch them struggle!
Madeline

The complexity of the solution depends on what exactly is the behavior of the sorting system.

If the app wants to show only the states that start with the letter “A”, we can filter out all the states that start with “A”

//due to code.org array.filter function not working, i will be implementing my own filter function
function filter(array, callback){
    var response = [];
    for (var i = 0; i<array.length; i++){
        if (callback(array[i])) {
            response.push(array[i]);
        }
    };
    return response;
}
var result = filter(["Apple", "Banana", "Avocado", "Grapes"], function(entry){
    return entry.substring(0, 1) === "A";
});
console.log(result); // ["Apple", "Avocado"]

If the app wants to sort alphabetically, the solution would be a bit more complicated extremely simple.

var result = states.sort();
console.log(result);

I don’t think how to do it is the issue. I try my best to follow Madeline’s lead because she knows more than I do.

What she is saying here is to have the student go back and look at what was taught to find either a code technique that we teach or an alternate design solution to accomplish the goal using what we teach. We don’t teach a direct solution to this in AP CSP. Since we are not allowed to just give a direct solution to our students all we can do is encourage and watch.

2 Likes

In terms of looking elsewhere there are some good Javascript books that can be downloaded for free. What you need to tell the students is look for ES5 version books. Those will be compatible with App Lab.

A book I would recommend to students is here http://speakingjs.com/es5/index.html#toc_ch01. It starts off with basic syntax and builds on that.

One reference that I like is https://www.w3schools.com/js/default.asp. But it isn’t all ES5 so some of it won’t apply. I like it because it has a list of topics down the left side. A student can browse easily. It also has examples and a unique try it button that lets you try the example and experiment with it. EIPM.

Drat - I mixed up the frameworks. Sorting and substrings are part of CSA not CSP. A filter is probably the best option given the CSP content (though they are in the documentation if a student were to hunt), BUT Don is correct that if the heart of this question is, “how do I help my student” then the frustrating answer is, “for the Create task the student is on their own”.

If you don’t feel like the student has the content knowledge to complete the task they are attempting (because its not part of the course - not because they’ve forgotten it), then it is perhaps also helpful to put this project in context for them. The goal is NOT to do something really complicated and exciting (though exciting/engaging to the student is always a plus), the goal is to demonstrate to college board that they are able to complete the programming tasks that align to the rubric. If they are getting stumped on a portion of the project that is interesting, but ultimately does not demonstrate a particular goal on the rubric then it may be time to reassess their project design. The thing they are getting stumped on or the grand project that they’ve thought of could be an awesome tangent passion project and as such would totally be something you could support them on.

2 Likes

I found it! We do teach substring.

Thank you all for all your help. To be clear, I have no intention of giving the solution to the student so he does it with aid. More than anything, I just wanted to know as an instructor for circumstances where I can share it and understand it better conceptually to give advice or guidance in accordance with the academic integrity of the project.

More than anything, I just need to learn the content better :sweat_smile:

Let me say this then, unit 5 presentation slide 153. Do you have questions about that slide?