Code Monkey home page Code Monkey logo

love-triangle's Introduction

Love triangles

History

Spichonees (made-up name) live in country Spichland where are no gender. Spichonees are big lovers, so each Spichonee loves any another Spichonee. Unfortunately there are sometimes situations, when Spichonee A loves Spichonee B, Spichonee B loves Spichonee C and Spichonee C loves Spichonee A. This phenomenon is called Love triangle.

Task

Your task is to implement function getLoveTrianglesCount which calculates how many love triangles phenomenons take place. The function takes the array of integers as the only parameter. An integer k on nth place means, that nth Spichonee loves kth Spichonee.

For example:

                                  // 1  2  3  Spichonees
  let count = getLoveTrianglesCount([2, 3, 1]);
  console.log(count); // 1
  /**
    1st Spichonee loves 2nd Spichonee.
    2nd Spichonee loves 3rd Spichonee.
    3rd Spichonee love 1st Spichonee.
    There is love triangle.
  */

Write your code in `src/index.js. Be sure, that all tests are positive. That means you cannot catch any error in tests.

Prepare and test

  • Install Node.js
  • Clone this repository: git clone https://github.com/yankouskia/love-triangle.git
  • Go to folder love-triangle
  • Run npm install in command line
  • Run npm test in command line
  • You will see the number of passing and failing tests

love-triangle's People

Contributors

klayder avatar

Watchers

James Cloos 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.