[Functional Programming] Discard the High and Low Values From an Array of Numbers with Ramda
The and of with from Array an Programming
2023-09-14 09:00:46 时间
In this lesson we'll see how to use the without
function to remove items in a known list from an array. Then we'll generate our exclusion list and apply it to without
using reduce
, min
, max
and converge
to detect the highest and lowest values in an array and creating a new array that excludes those values.
import {without, min, max, reduce, converge, identity, equals} from 'ramda' const getLowest = reduce(min, Number.MAX_VALUE) const getHighest = reduce(max, Number.MIN_VALUE) const getExcluded = converge((a, b) => [a, b], [getLowest, getHighest]) // From const dropHighLow2 = numbers => { /* // version 1 const lowest = getLowest(numbers) const highest = getHighest(numbers) return without([lowest, highest], numbers); */ /* // version 2 return without(getExcluded(numbers), numbers); */ // version 3 return converge(without, [getExcluded, identity])(numbers) } // To const dropHighLow = converge(without, [getExcluded, identity]) const res = dropHighLow([1,2,3,4,5,6,7,8]) console.log(res, equals(res, [2,3,4,5,6,7]))
相关文章
- Linux pip错误分析 (Running pip as the ‘root‘ user can result in broken permissions and conflict)
- 【错误记录】Android Studio 创建报错 ( The length of the module location exceeds the limit of 100 characters. )
- ORA-22900: the SELECT list item of THE subquery is not a collection type ORACLE 报错 故障修复 远程处理
- ORA-26747: The one-to-many transformation function string encountered the following error: string ORACLE 报错 故障修复 远程处理
- ORA-28086: The evaluation of the policy expression failed. string ORACLE 报错 故障修复 远程处理
- ORA-31128: The event handler calls cannot exceed the depth of string ORACLE 报错 故障修复 远程处理
- ORA-38408: The ADT “string” does not exist in the current schema. ORACLE 报错 故障修复 远程处理
- ORA-41104: The database: string is the Cluster Director. ORACLE 报错 故障修复 远程处理
- ORA-46015: The value of the “paramDatatype” element is too long. ORACLE 报错 故障修复 远程处理
- ORA-48444: The single “.” and “*” cannot appear in the middle of the path ORACLE 报错 故障修复 远程处理
- ORA-48490: The field number exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-13621: The task_or object string is marked as a template and cannot perform the requested operation. ORACLE 报错 故障修复 远程处理
- ORA-13633: The task string was interrupted and needs to be resumed. ORACLE 报错 故障修复 远程处理
- ORA-15247: cannot specify both WAIT and NOWAIT options in the same statement ORACLE 报错 故障修复 远程处理
- Mysql主从架构报错-Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work…详解数据库
- what is the difference of select single and select up to one row in abap详解编程语言
- 多条件查询MySQL中使用And多条件查询的步骤(mysql中and)
- The Power of Linux: Unleashing the Potential of OpenSource Software(linux英文)
- The Power of ESL and Oracle for a Smarter Future(esloracle)
- The Power of the Hydra Oracle: Unlocking Potential(hydraoracle)
- Exploring the Features and Enhancements of Linux 4.9(linux4.9)
- Exploring the Power of Linux Labeling: Enhancing Security and Organization(linuxlabel)
- Exploring the World of MySQL Driver: Unleashing Its Performance and Functionality(mysql的驱动)
- Exploring the Power of Linux 2G: A Guide to Maximizing Performance and Efficiency(linux2g)
- Exploring the Key Differences Between Redis Sharding and Clustering(redis分片和集群区别)
- Exploring the Power of Linux with C and Assembly Language(linuxc汇编)
- Exploring the Power of Linux Stat and Understanding Its Impact on File Management(linuxstatm)
- Maximizing Database Efficiency: The Ultimate Guide to Implementing MSSQL Sharding and Partitioning(mssql分表分库)
- Exploring the Benefits of Storing Data with MongoDB and XML(mongodbxml)
- Exploring the Functions and Applications of Eth0 in Linux(linux中的eth0)
- Exploring the Benefits and Advantages of Using MongoDB for .NET Development(mongodbnet)