GithubHelp home page GithubHelp logo

4hmetuyar / codesignal Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 189 KB

Samples and descriptions made on codesignal.

Home Page: https://app.codesignal.com

License: MIT License

JavaScript 93.06% C# 6.11% PLpgSQL 0.40% PLSQL 0.42%

codesignal's Introduction

1. Add

Write a function that returns the sum of two numbers.

Example :

  • For param1 = 1 and param2 = 2, the output should be add(param1, param2) = 3.

Solution :

function add(param, ...otherParams) {    
    return param + (otherParams.length ? add(...otherParams) : 0);
}

2. CenturyFromYear

Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc.

Example :

  • For year = 1905, the output should be centuryFromYear(year) = 20;
  • For year = 1700, the output should be centuryFromYear(year) = 17.

Solution :

function centuryFromYear(year) {
return Math.floor((year-1)/100) + 1;
}

3. CheckPalindrome

Given the string, check if it is a palindrome. (A palindrome is a string that reads the same left-to-right and right-to-left.)

Example :

  • For inputString = "aabaa", the output should be checkPalindrome(inputString) = true;
  • For inputString = "abac", the output should be checkPalindrome(inputString) = false;
  • For inputString = "a", the output should be checkPalindrome(inputString) = true.

Solution :

function checkPalindrome(inputString) {
    return inputString == inputString.split('').reverse().join('');
}

4. AdjacentElementsProduct

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.

Example :

  • For inputArray = [3, 6, -2, -5, 7, 3], the output should be adjacentElementsProduct(inputArray) = 21.

7 and 3 produce the largest product.

Solution :

function adjacentElementsProduct(inputArray) {
 var cb = Number.NEGATIVE_INFINITY;
    for(var i=0;i<inputArray.length-1;i++){
        if(inputArray[i]*inputArray[i+1] > cb){
          cb = inputArray[i]*inputArray[i+1];
        }
    }
  return cb;
}

5. ShapeArea

Below we will define an n-interesting polygon. Your task is to find the area of a polygon for a given n.

A 1-interesting polygon is just a square with a side of length 1. An n-interesting polygon is obtained by taking the n - 1-interesting polygon and appending 1-interesting polygons to its rim, side by side.

Example :

  • For n = 2, the output should be shapeArea(n) = 5;
  • For n = 3, the output should be shapeArea(n) = 13.

Solution :

function shapeArea(n) {
    return 2*Math.pow(n,2) - 2*n +1;
}

codesignal's People

Contributors

4hmetuyar avatar

Stargazers

 avatar

Watchers

 avatar  avatar

codesignal's Issues

Box Blur issues

Last night you partied a little too hard. Now there's a black and white photo of you that's about to go viral! You can't let this ruin your reputation, so you want to apply the box blur algorithm to the photo to hide its content.

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.