In this lesson we'll look at how you can use Ramda's unfold function to generate a list of values based on an initial seed.
const R = require('ramda');

// if return false, then stop iteration
// [n1, n2]: n1 is the value to be added to the result array
// n2: is the value return to next iteration as a starting value
const throughNByOne = R.curry((limit, n) => n > limit ? false: [n, n + ]);
const throughNByBaseTwo = R.curry((limit, n) => n > limit ? false: [n, n * ]); const res1 = R.unfold(throughNByOne(), ); // [ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
console.log(res1); const res2 = R.unfold(throughNByBaseTwo(), ); // [ 2, 4, 8, 16, 32, 64, 128, 256 ]
console.log(res2);

[Ramda] Create an Array From a Seed Value with Ramda's unfold的更多相关文章

  1. [Ramda] Create a Query String from an Object using Ramda's toPairs function

    In this lesson, we'll use Ramda's toPairs function, along with map, join, concatand compose to creat ...

  2. [Ramda] Filter an Array Based on Multiple Predicates with Ramda's allPass Function

    In this lesson, we'll filter a list of objects based on multiple conditions and we'll use Ramda's al ...

  3. [Python Cookbook] Numpy: Multiple Ways to Create an Array

    Convert from list Apply np.array() method to convert a list to a numpy array: import numpy as np myl ...

  4. JavaScript interview Question - Create a Array with two papameters without using loop!

    JavaScript interview Question - Create a Array with two papameters without using loop! JavaScript - ...

  5. [Javascript] Create an Array concatAll method

    In addition to flat Arrays, programmers must often deal with nested Arrays. For example let's say we ...

  6. [Ramda] Declaratively Map Data Transformations to Object Properties Using Ramda evolve

    We don't always control the data we need in our applications, and that means we often find ourselves ...

  7. [Ramda] Refactor a Promise Chain to Function Composition using Ramda

    Promise chains can be a powerful way to handle a series of transformations to the results of an asyn ...

  8. forEach 方法 (Array) (JavaScript)

    为数组中的每个元素执行指定操作. 语法 array1.forEach(callbackfn[, thisArg]) 参数 参数 定义 array1 必选.一个数组对象. callbackfn 必选.最 ...

  9. create feature from text file

    '''---------------------------------------------------------------------------------- Tool Name: Cre ...

随机推荐

  1. HTML的SEO(搜索引擎优化)标准

    HTML的SEO(搜索引擎优化)标准 一.总结 这个做seo的时候要多看,做网站优化的时候 1. SEO(搜索引擎优化):通过总结搜索引擎的排名规律,对网站进行合理优化,使你的网站在百度和Google ...

  2. web自动化测试 Selenium2 Java自动化测试实战9_3

    driver.findElement(By.id("idInput")).sendKeys("哈哈"); driver.findElement(By.id(&q ...

  3. 理解spring对事务的处理:传播性

    所谓事务传播行为就是多个事务方法相互调用时,事务如何在这些方法间传播.Spring 支持 7 种事务传播行为: PROPAGATION_REQUIRED 如果当前没有事务,就新建一个事务,如果已经存在 ...

  4. COGS——C 908. 校园网 || 洛谷——P 2746 [USACO5.3]校园网Network of Schools

    http://www.cogs.pro/cogs/problem/problem.php?pid=908   ||  https://www.luogu.org/problem/show?pid=27 ...

  5. Stable Matching (Gale Sharpley Algorithm)

    稳定婚配问题:n个男生n个女生.当中每一个人都有自己心仪的列表. 问怎样达成稳定的匹配(比方, b想B求婚,可是B已有的对象的优先级高于b,此时b的魅力不足以拆散B所处的那一对,即达到稳定状态.) ( ...

  6. vue的使用(一)

    之前找了一个学前端的同学,给我免费做几个页面,但是后来也就杳无音信了,今天脑子发热自己学一下vue算了. 本节目标:      安装以及数据绑定 1.安装和运行 ·必须要安装nodejs,这个到网上写 ...

  7. js的AJAX请求有关知识总结

    什么是AJAX?AJAX作用是什么? async javascript and xml(异步的javascript和xml) 作用:实现局部刷新 async:我们真实项目中一般使用AJAX从服务器端获 ...

  8. Spring Boot 动态数据源(Spring 注解数据源)

    本文实现案例场景:某系统除了需要从自己的主要数据库上读取和管理数据外,还有一部分业务涉及到其他多个数据库,要求可以在任何方法上可以灵活指定具体要操作的数据库. 为了在开发中以最简单的方法使用,本文基于 ...

  9. [spark]Spark Streaming教程

      (一)官方入门示例 废话不说,先来个示例,有个感性认识再介绍. 这个示例来自spark自带的example,基本步骤如下: (1)使用以下命令输入流消息: $ nc -lk 9999 (2)在一个 ...

  10. 关于stm32的启动模式

    1)用户闪存 = 芯片内置的Flash,这个应该就是在Keil中选择那个,每个芯片的flash不一样,具体可以在建立工程时查看内置flash的大小. 2)SRAM = 芯片内置的RAM区,就是内存啦. ...