Coder Social home page Coder Social logo

test-task-5500's Introduction

test-task-5500

Тестовое задание на 5500-6000$

  • Assume most recent language standard are available (ES6)
  • We expect good performance.
  • If missing more requirements details, just make reasonable assumptions of your own.
  • Solution must be simple and compact. No defensive coding, no comments, no unrequested features. Only one file 10-20 lines of code
  • Work only inside Google Docs: no external editor/IDE/debugger, no copy-paste to/from such an editor. We must see the flow of how you write the code.

Note: you have a total of 60 minutes for both questions!

Task 1

Implement function verify(text) which verifies whether parentheses within text are correctly nested. You need to consider three kinds: (), [], <> and only these kinds.

Examples:

verify("---(++++)----") -> 1
verify("") -> 1
verify("before ( middle []) after ") -> 1
verify(") (") -> 0
verify("<(   >)") -> 0
verify("(  [  <>  ()  ]  <>  )") -> 1
verify("   (      [)") -> 0

Task 2

Problem Simplify the implementation below as much as you can.

Even better if you can also improve performance as part of the simplification! FYI: This code is over 35 lines and over 300 tokens, but it can be written in 5 lines and in less than 60 tokens. Function on the next page.

function func(s, a, b) {
    var match_empty=/^$/ ;
    if (s.match(match_empty)) {
      return -1;
    } else {
        var i=s.length-1;
        var aIndex=-1;
        var bIndex=-1;

        while ((aIndex==-1) && (bIndex==-1) && (i>=0))
        {
            if (s.substring(i, i+1) == a)
                aIndex=i;
        	if (s.substring(i, i+1) == b)
                bIndex=i;

        	i--;
        }

        if (aIndex != -1)
        {
            if (bIndex == -1)
                return aIndex;
        	else
                return Math.max(aIndex, bIndex);
        }
        else
        {
            if (bIndex != -1)
                return bIndex;       
	      else
                return -1;
        }
    }
};

test-task-5500's People

Contributors

gizmodevdev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.