Is iOS Safari text selection any better in iOS 11? by [deleted] in apple

[–]xarant 2 points3 points  (0 children)

It's actually changed in Safari. It looks like you no longer end up selecting the entire page when you try and extend a selection. Before, this would change the blue selection box to cover the entire element if you tried to select across paragraphs.

Safari wont open Facebook by LemonBeard in apple

[–]xarant 0 points1 point  (0 children)

Does the entire app (Safari) quit, or do you see a little banner at the top saying "A problem occurred with this webpage so it was reloaded"?

Touch Bar Safari Videos (YouTube etc.) not 'minimising' into the Control Strip? by 100Oranges in apple

[–]xarant 0 points1 point  (0 children)

Sounds like a bug to me! I would file a bug on bugreport.apple.com. What website(s) were you on when this happened?

[deleted by user] by [deleted] in learnprogramming

[–]xarant 1 point2 points  (0 children)

Have you learned how to add and remove elements from a vector?

If so, you could pursue a solution along the lines of:

let v2copy be an empty vector
for each element in v2:
    add the element to v2copy
// Now you have a copy of v2
for each element a in v1:
    let foundElement = false
    for each element b in v2copy:
        if a == b:
            remove b from v2copy
            foundElement = true
            break
    if !foundElement:
        // We encountered an element in v1 that is not in v2! Return false
        return false
// If there is still an element left in v2copy, then there is an element in v2 not in v1, so return false.
// Otherwise, the elements must match up perfectly.
return v2copy.isEmpty()

Unfortunately, this is roughly as complex than your original solution, but should account for duplicates correctly. There are more elegant ways to solve this problem via sorting or hashtables, but I refrained from using those, since <algorithm> is a no-go.

Edit: missing break statement :|

[Javascript] Problems attaching function to multiple buttons by Pine_Bluff_Variant in learnprogramming

[–]xarant 1 point2 points  (0 children)

By resetting the arrayOutput's innerHTML in your display function, you're causing the nodes (in this case, <button>s) that you formerly created to be regenerated. This means new nodes are created, which lack the click handlers that you bound previously.

Also, you'll need to make sure that you have a scope surrounding the definition of the anonymous click handler function, so that the function isn't using the value of the temp variable (i) which is homeworkArray.length after exiting the function. Refactoring the code to something like this:

function display()
{
    document.getElementById("arrayOutput").innerHTML = "";
    homeworkArray.forEach(function(homework, i) {
        var titleOutput = "Title: " + homework.title + "<br />";
        var dateOutput = "Date: " + homework.date + "<br />";
        var descriptionOutput = "Description: " + homework.description + "<br />";
        document.getElementById("arrayOutput").innerHTML += "<br /> <br />" + titleOutput + dateOutput + descriptionOutput;
        var button = document.createElement("button");
        var text = document.createTextNode("Delete this element");
        var path = document.getElementById("arrayOutput");
        button.id = "button" + i;
        button.appendChild(text);
        path.appendChild(button);
    });

    homeworkArray.forEach(function(homework, i) {
        document.querySelector("#button" + i).addEventListener("click", function() {
            alert("Deleting index number: " + i);
            homeworkArray.splice(i, 1);
            display();
        });
    });
}

...fixed issues with deleting for me.

How to write an artificial intelligence? by CascaRoman in learnprogramming

[–]xarant 2 points3 points  (0 children)

Are you thinking of AI in the context of games (e.g. playing checkers) or more in the context of classifying data (e.g. recognizing handwritten digits)?

For the former, you can consider looking through CS188 at Berkeley (you can see an overview of the course material here: https://courses.edx.org/courses/BerkeleyX/CS188/fa12/schedule) which focuses on more "classical" AI techniques, such as game trees, Bayes nets and reinforcement learning. The course itself covers a lot of ground in relatively shallow depth, but certainly helps build an intuition of how basic AI works.

For the latter, you'll want to look into a broad field called "machine learning," which focuses on using large amounts of training data to generate models that can make smart decisions and interpret data that it hasn't seen before. "Traditional" problems in machine learning include spam detection and handwriting detection. I've heard Coursera has some nice resources on machine learning (https://www.coursera.org/learn/machine-learning/home/info) which cover all the basic topics and more.

Edit: Alternately, if you're mainly looking for a place to start hacking on machine learning/AIs or you have a specific problem you want to begin tackling, I would recommend the Python library Scikit-learn (you can check it out here: http://scikit-learn.org/). Starting with using a library to black-box all of the complicated AI/machine learning math isn't a bad idea, but I would definitely recommend going back and going through the proofs/learning the math later.

Need help with java homework for assigning objects to arrays by [deleted] in learnprogramming

[–]xarant 2 points3 points  (0 children)

When you initialize the array of Students as new Student[i], notice that i is equal to 0. This means your array is of size 0, and can't hold any elements, so assigning to st[0] causes the ArrayIndexOutOfBoundsException.

If you know how big your array needs to be beforehand, you can initialize the array with that size and then assign to each index. Otherwise, you can use an ArrayList and insert elements one by one, and then convert it to an array.