Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
RamdaJS is it overkill trying to point-free every function

I recently got into functional programming bit by bit; started trying to point-free every function I code today.

I was practicing using Ramda while I was coding a binary search algorithm.

const R = require("ramda");

const getMidIndex = R.compose(
  R.call(R.invoker(1, "floor"), R.__, Math),
  R.divide(R.__, 2),
  R.apply(R.add),
  R.props(["upper", "lower"])
);

const getMidElement = R.converge(R.nth, [getMidIndex, R.prop("list")]);
const getSearchValue = R.prop("searchValue");

var binarySearch = R.compose(
  R.prop("ans"),
  R.until(
    R.either(
      R.compose(R.not, R.compose(R.isNil, R.prop("ans"))),
      R.compose(R.apply(R.gt), R.props(["lower", "upper"]))
    ),
    R.cond([
      [
        R.converge(R.equals, [getSearchValue, getMidElement]),
        R.converge(R.assoc("ans"), [getMidIndex, R.identity]),
      ],
      [
        R.converge(R.lt, [getSearchValue, getMidElement]),
        R.converge(R.assoc("upper"), [
          R.compose(R.dec, getMidIndex),
          R.identity,
        ]),
      ],
      [
        R.converge(R.gt, [getSearchValue, getMidElement]),
        R.converge(R.assoc("lower"), [
          R.compose(R.inc, getMidIndex),
          R.identity,
        ]),
      ],
    ])
  ),
  R.converge(R.assoc("upper"), [
    R.compose(R.dec, R.length, R.prop("list")),
    R.assoc("lower", 0),
  ]),
  R.assoc("ans", null),
  R.converge(R.mergeLeft, [
    R.compose(R.objOf("list"), R.nthArg(0)),
    R.compose(R.objOf("searchValue"), R.nthArg(1)),
  ])
);

var binarySearch = R.curryN(2, binarySearch);

module.exports = binarySearch;

the function takes two inputs a list and a value(v) -then-> the first three composing collecting args in an object like this

{
  searchValue: 7,
  list: [ 2, 3, 7, 12 ],
  ans: null,
  lower: 0,
  upper: 3
}

after finishing I started to wonder from the performance point of view is this worse than having just one local midElement for example instead to keep calculating it am I on the right track or just wasting time is this even readable

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda