This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUESTION 1 | |
TIME: 10 minutes | |
Number is a palindrome if it is equal to the number with digits in reversed order. For example, 5, 44, 171, 4884 are palindromes and 43, 194, 4773 are not palindromes. | |
Write a method palindrome_chain_length which takes a positive number and returns the number of special steps needed to obtain a palindrome. The special step is: "reverse the digits, and add to the original number". If the resulting number is not a palindrome, repeat the procedure with the sum until the resulting number is a palindrome. | |
If the input number is already a palindrome, the number of steps is 0. | |
Input will always be a positive integer. | |
For example, start with 87: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUESTION 2 | |
TIME: 5 minutes | |
What is the output of this line of code? | |
console.log((function x(n){return ((n > 1) ? n * x(n-2) : n)})(10)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codephillip.hello; | |
public class Main { | |
public static void main(String[] args) { | |
divider(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUESTION 5 | |
CREDIT: http://www.cs.unc.edu/~stotts/COMP204/refactor/chap1.html | |
TIME: 15 minutes | |
Refactor the following code | |
public class DomainObject { | |
public DomainObject (String name) { | |
_name = name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUESTION 4 | |
TIME: 5 minutes | |
What will be the output of this code? | |
var x = 21; | |
var girl = function () { | |
console.log(x); | |
var x = 20; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUESTION 3 | |
TIME: 5 minutes | |
Consider the following code. What will the output be, and why? | |
(function () { | |
try { | |
throw new Error(); | |
} catch (x) { | |
var x = 1, y = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download_invoice(self, request, pk=None): | |
""" | |
Download Invoice Endpoint | |
--- | |
omit_serializer: True | |
omit_parameters: | |
- query | |
""" | |
current_url = '{}?{}'.format( | |
reverse(request.resolver_match.url_name, kwargs={'pk': pk}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void parseXML(String targetFilePath) { | |
try { | |
FileInputStream is = new FileInputStream(targetFilePath); | |
XmlToJson xmlToJson = new XmlToJson.Builder(is, null).build(); | |
JSONObject jsonObject = xmlToJson.toJson(); | |
Timber.d("Content " + jsonObject.toString()); | |
// get the root key. | |
// This prevents us from manually checking key. This is a special case | |
Iterator keys = jsonObject.keys(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getFileContent(String targetFilePath) { | |
try { | |
FileInputStream fis = new FileInputStream(targetFilePath); | |
DataInputStream in = new DataInputStream(fis); | |
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | |
String strLine; | |
StringBuilder sb = new StringBuilder(); | |
while ((strLine = br.readLine()) != null) | |
sb.append(strLine); | |
Timber.d("form data"); |