Skip to content

Instantly share code, notes, and snippets.

View followyouhome's full-sized avatar

Vladislav Pozniak followyouhome

  • Minsk, Belarus
View GitHub Profile
@followyouhome
followyouhome / index.md
Created July 28, 2020 12:42
Test gist for hashtag-labs.com

Question 1: Suppose you have a webpage that contains the following IMG tag.

<img id=”myimage” src=”https://hashtag-labs.com/banner.jpeg” width=”300” height=”250” />

You can assume that any other HTML on this webpage is unknown, but valid.

Write a short script that does the following:

  • Every 2 seconds
  • If 100% of the image’s pixels are inside the browser viewport
@followyouhome
followyouhome / gist:1b488a621cc2f1b3a52d2676883e018f
Last active January 8, 2019 21:50
Test gist for ilabsinc.com

Answer 1

Nothing special - indexOf() will return -1 in case of mismatch, not false or zero because we need zero just in case that was catched by QA. Honestly in ES6/ES7 world we already have includes() that will fit better in our case - we don't need to know substring position, just is it included or not. Or maybe RegExp with special flag that will ignore case. But because of initial requirenments my answer is:

function validateString(str) {
    if (str.toLowerCase().indexOf('superman') === -1) {
 throw new Error('String does not contain superman');