Code Monkey home page Code Monkey logo

ebs-integrator-challenge's Introduction

EBS FE Test 1

Requirements:

  1. Typescript
  2. TS Compiler
  3. ESLint + Prettier

Getting started:

  1. Type yarn to install necessary dependencies.
  2. Type yarn build to compile your code.
  3. Type yarn run to run your code and see the result on terminal.

Todo:

(scroll down to see more information about every task)

  1. Create reduce function
  2. Create find function
  3. Create concat function
  4. Create pipe function

All the functions should not use regular Array.prototype.reduce(), Array.prototype.concat() or Array.prototype.find(), they should be realized using only for(), while() and etc ..

reduce(arr, (stop) => (acc, current, index) => {}, initialValue)

  • It should have functionality to stop cycle using stop function
const arr = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const obj = reduce(
  arr,
  (stop) => (acc, current, index) => {
    if (index === 3) {
      stop();
    }

    return { ...acc, [index]: current };
  },
  {}
);

console.log(obj); // Result: { 0: 'spray', 1: 'limit', 2: 'elite' }

find(arr, (item, index) => {})

const arr = [
  { id: 0, name: 'spray' },
  { id: 1, name: 'limit' },
];

console.log(find(arr, (item) => item.id === 1)); // Result: { id: 1, name: 'limit' }
console.log(find(arr, (item) => item.id === 10)); // Result: undefined

concat(arr1, arr2, arr3, ...)

  • The number of arrays should be unlimited. It can be 2, 3 or even 10.
const arr1 = ['spray', 'limit', 'elite'];
const arr2 = ['exuberant', 'destruction'];
const arr3 = ['present'];

concat(arr1, arr2); // Result: ['spray', 'limit', 'elite', 'exuberant', 'destruction']
concat(arr1, arr2, arr3); // Result: ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present']

pipe(arr, [concat(), reduce(), find(), ...])

  • All functions such as reduce, find & concat should not expect first argument (array) in case when they're in a pipe, it should be passed automatically.
const arr1 = ['spray', 'limit', 'elite'];
const arr2 = ['exuberant', 'destruction'];
const arr3 = ['present'];

pipe(arr1, [
  concat(arr2, arr3), // Result: ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present']
  reduce(
    (stop) => (acc, current, index) => {
      if (acc.length === 2) {
        stop();
      }

      // get only even elements
      if (index % 2 == 0) {
        acc.push({ index, label: current });
      }

      return acc;
    },
    []
  ), // Result: [{ index: 2, label: 'limit' }, { index: 4, label: 'exuberant' }]
  find((item) => item.label.length > 5), // Result { index: 4, label: 'exuberant' }
]);

// Result { index: 4, label: 'exuberant' }

ebs-integrator-challenge's People

Watchers

 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.