[Solved] How to modify “this” in javascript

You can use .call(context[, params])and .apply(context[, arguments]) to do this. For example: function move(x, y) { this.style.left = x + “px”; this.style.top = y + “px”; }; // now this in move refers to the div element move.call($(‘div’)[0], 100, 200); But you can’t just overwrite this. solved How to modify “this” in javascript

[Solved] Python – Put new line into file at largest indent

You may want a code something like – start = 1 lines = [‘Step’ + str(start) + ‘:\n’] with open(‘file.txt’,’r’) as inF: prevspace = -1 for line in inF: lspaces = len(line) – len(line.lstrip()) if lspaces > prevspace and prevspace != -1: lines.append(‘Step’ + str(start+1) + ‘:\n’) start = start + 1 lines.append(line) prevspace = … Read more

[Solved] Maximum tree depth in Haskell

You would want to write a recursive function to do this. For each Tree constructor, you’ll need a different case in your function. To start with, you know that the depth of any Leaf is 1, so maxDepth :: Tree -> Int maxDepth (Leaf _) = 1 maxDepth (Branch2 c left right) = maximum [???] … Read more

[Solved] I can’t access Genre class

As JohnnyMopp mentioned above, you don’t add any genre into list. Change your code like following: public Catalogue() { this.genres = new LinkedList<Genre>(); Genre programming = new Genre(“Programming”); Genre drama = new Genre(“Drama”); this.genres.add(programming); this.genres.add(drama); booksAvailable.add(new Book(“Swift”, 1999, programming, 20)); booksAvailable.add(new Book(“TheAlChemist”, 2000, drama, 20)); //Name of a book, year of publication, genre, price } … Read more

[Solved] Rewrite regex to accept conditional terms

Your regex doesn’t say what you think it says. ^([a-z0-9_\.-])+@[yahoo]{5}\.([com]{3}\.)?[com]{3}$ Says any characters a-z, 0-9, ., – one or more times. That later part where you are trying match yahoo.com is incorrect. It says y, a, h, or o, any of those characters are allowed 5 times. Same with the com so aaaaa.ooo would be … Read more

[Solved] Stringoutofboundexception for string

i know scan.nextline() gives a character No, it gives a string. So is there anyway to handle an exception in such a way that i am able to manage to keep string after scan.nextline(). The real problem is that you are not handling the case where nextLine() returns an empty string. You cannot retrieve characters … Read more

[Solved] Why is My Program not Working [closed]

EUREKA!!!!!! I finally came up with a working solution. No more errors. I’m calling it version 2.0.0 I’ve uploaded it online, and here’s the link [version 2.0.0] http://mibpaste.com/3NADgl All that’s left is to go to excel, and derive the final states of the door and be sure, that it’s working perfectly. Please take a look … Read more

[Solved] Parse a string in php

Use PHP’s pathinfo() function: http://php.net/manual/en/function.pathinfo.php $info = pathinfo(‘items/category/test.txt’); $dirPath = $info[‘dirname’]; // OR $dirPath = pathinfo(‘items/category/test.txt’, PATHINFO_DIRNAME); // Output: items/category solved Parse a string in php

[Solved] Java realtime writing file when it’s opened

Interesting: Lets deal this in simple way. 1. Save a file test.txt somewhere. 2. Open that file and keep it opened In Java write to this file (Standard Code) FileWriter fw = new FileWriter(new FileOutputStream(new File(“c:/test.txt”))); fw.write(“ABC”) Now go to notepad file again. I normally used Textpad it does refresh automatically (by an alert) because … Read more

[Solved] The right way to copy map elements

Considering that your map values are maps themselves, copying those inner maps will be quite expensive. It’s probably slightly cheaper to use pointers to the inner maps than to use iterator, but both are significantly cheaper than copying the inner maps. However, whether you use pointers or iterators, make sure that they’re not invalidated. The … Read more