Skip to content

Instantly share code, notes, and snippets.

@rajankur
Last active July 5, 2018 06:37
Show Gist options
  • Save rajankur/1faca3e3352cc879eb74 to your computer and use it in GitHub Desktop.
Save rajankur/1faca3e3352cc879eb74 to your computer and use it in GitHub Desktop.
The problems focuses on testing your programmatic, algorithmic and code writing skills. We would love to get the solutions the "Object Oriented" way. Do not copy :)

Problem 1: write a function to get the value from an array in such a way that the keys are sparated by a dot.

function array_take($array, $keymap) {
    # your code goes here...
}
$person = [
    'name' => [
        'firstname' => 'Raj',
        'lastname' => 'Ankur'
    ],
    'employee' => [
        'engineering' => [
            'position' => 'Hacking Intern'
         ]
     ]
];

In the below statement $x should be equal to 'Hacking Intern':

$x = array_take($person, 'employee.engineering.position');

Problem 2: Assume you have a web page opened: "https://www.picsdream.com/search?q=a&cities=delhi&area=chanakya-puri". Write a function input() that does following operations.

echo input(); # Output 1: q=a&cities=delhi&area=chanakya-puri
echo input('q'); # Output 2: a
echo input(['q', 'cities']); # Output 3: q=a&cities=delhi
count(input(['q', 'cities'])); # Output 4: 2
count(input()); # Output 5: 3
echo input()->append(['another_var' => 'value']); # Output 6: q=a&cities=delhi&area=chanakya-puri&another_val=value
echo input()->append(['another_var' => 'value'])->except('a'); # Output 7: cities=delhi&area=chanakya-puri&another_val=value

Problem 3: Write a function to return current financial year

function fy() {
    #Your code goes here
}
echo fy(); // Output: 2018-19

Problem 4: Write a function to beautify numbers in such a way that the number is Round-up of Round-down to nearest 49 or 99

function beautify_price() {
    #Your code goes here
}
echo beautify_price(26); // Output: 49
echo beautify_price(78); // Output: 99
echo beautify_price(69); // Output: 49
echo beautify_price(1715); // Output: 1699
echo beautify_price(2489); // Output: 2499

Problem 5: What will be the output of following JavaScript code snippet? Explain your answer.

const numbers = [1, 2, 3, 4];
for (var i = 0; i < numbers.length; i++) {
  setTimeout(function() {
    console.log('index: ' + i + ', element: ' + numbers[i]);
  }, 5000);
}

Problem 6: Create a masonary layout using HTML, CSS & JavaScript/jQuery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment