Comparing version 0.1.0 to 0.2.0
@@ -1,4 +0,40 @@ | ||
const R = require("../rambdax") | ||
const R = require("../rambdaxX") | ||
const numArr = [0,1,2,3,4] | ||
const obj = {a:1,b:2} | ||
describe("allPass",()=>{ | ||
it("when returns true",()=>{ | ||
const conditionArr = [ | ||
val => val.a === 1, | ||
val => val.b === 2, | ||
] | ||
expect( | ||
R.allPass(conditionArr,obj) | ||
).toBeTruthy() | ||
}) | ||
it("when returns false",()=>{ | ||
const conditionArr = [ | ||
val => val.a === 1, | ||
val => val.b === 3, | ||
] | ||
expect( | ||
R.allPass(conditionArr,obj) | ||
).toBeFalsy() | ||
}) | ||
}) | ||
describe("Rambdax",()=>{ | ||
describe("all",()=>{ | ||
it("when returns true",()=>{ | ||
const fn = val => val > -1 | ||
expect(R.all(fn,numArr)).toBeTruthy() | ||
}) | ||
it("when returns false",()=>{ | ||
const fn = val => val > 2 | ||
expect(R.all(fn,numArr)).toBeFalsy() | ||
}) | ||
}) | ||
describe("rangeBy",()=>{ | ||
it("",()=>{ | ||
@@ -19,2 +55,20 @@ expect( | ||
}) | ||
}) | ||
}) | ||
describe("pickBy",()=>{ | ||
it("",()=>{ | ||
const input = {a:1,b:2,c:3,d:4} | ||
const fn = val => val > 2 | ||
const expectedResult = {c:3,d:4 } | ||
expect(R.pickBy(fn,input)).toEqual(expectedResult) | ||
}) | ||
}) | ||
describe("omitBy",()=>{ | ||
it("",()=>{ | ||
const input = {a:1,b:2,c:3,d:4} | ||
const fn = val => val < 3 | ||
const expectedResult = {c:3,d:4 } | ||
expect(R.omitBy(fn,input)).toEqual(expectedResult) | ||
}) | ||
}) |
{ | ||
"name": "rambdax", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "rambda", | ||
@@ -29,4 +29,7 @@ "main": "index.js", | ||
"devDependencies": { | ||
"jest": "^19.0.2" | ||
"beautify-benchmark": "^0.2.4", | ||
"benchmark": "^2.1.4", | ||
"jest": "^19.0.2", | ||
"ramda": "^0.23.0" | ||
} | ||
} |
110
rambdax.js
@@ -9,11 +9,18 @@ const R = require("rambda") | ||
} | ||
const isInteger = !distance.toString().includes(".") | ||
if(startNum>endNum){ | ||
const startNumHolder = startNum | ||
startNum = endNum | ||
endNum = startNumHolder | ||
l(startNum, endNum) | ||
} | ||
const willReturn = [startNum] | ||
const isInteger = !distance.toString().includes(".") | ||
let valueToPush = startNum | ||
if(isInteger){ | ||
const loopIndexes = R.range(0,Math.floor((endNum-startNum)/distance)) | ||
for(const i of loopIndexes){ | ||
valueToPush += distance | ||
l(valueToPush) | ||
valueToPush += distance | ||
willReturn.push(valueToPush) | ||
@@ -27,21 +34,98 @@ } | ||
)(distance.toString()) | ||
console.log(startNum.toFixed(decimalLength)) | ||
console.log(endNum.toFixed(decimalLength)) | ||
const loopIndexes = R.range(0,Math.floor((endNum-startNum)/distance)) | ||
for(const i of loopIndexes){ | ||
valueToPush = valueToPush+distance | ||
valueToPush = valueToPush+distance | ||
willReturn.push(Number(valueToPush.toFixed(decimalLength))) | ||
} | ||
} | ||
return willReturn | ||
} | ||
function randomIndex(arr){ | ||
return arr[ Math.floor(arr.length * Math.random()) ] | ||
function omitBy(fn, obj){ | ||
if (obj === undefined) { | ||
return holder => omitBy(fn, holder) | ||
} | ||
const willReturn = {} | ||
for (prop in obj) { | ||
if (!fn(obj[prop],prop)) { | ||
willReturn[ prop ] = obj[ prop ] | ||
} | ||
} | ||
return willReturn | ||
} | ||
// TODO benchmark between the static export vs Object.keys(...) | ||
function pickBy(fn, obj){ | ||
if (obj === undefined) { | ||
return holder => pickBy(fn, holder) | ||
} | ||
const willReturn = {} | ||
for (prop in obj) { | ||
if (fn(obj[prop],prop)) { | ||
willReturn[ prop ] = obj[ prop ] | ||
} | ||
} | ||
return willReturn | ||
} | ||
const arg = {inputArgument: false,defaultArgument:true} | ||
function defaultTo({defaultArgument, inputArgument}){ | ||
if(inputArgument === undefined){} | ||
return inputArgument === undefined || !(R.type(inputArgument)===R.type(defaultArgument)) ? | ||
defaultArgument : | ||
inputArgument | ||
} | ||
function flip(fnToCurry){ | ||
return (...curryArguments)=>{ | ||
const len = fnToCurry.length | ||
if(curryArguments[1]===undefined){ | ||
if(len > 1){ | ||
return (...futureArguments) => { | ||
if(len === 3 && futureArguments.length === 1){ | ||
return holder => fnToCurry(holder,futureArguments[0],curryArguments[0]) | ||
} | ||
return fnToCurry(...futureArguments.reverse(),curryArguments[0]) | ||
} | ||
} | ||
}else if(curryArguments[2]===undefined && len === 3){ | ||
return (futureArgument) => fnToCurry(futureArgument, ...curryArguments.reverse()) | ||
} | ||
return fnToCurry(...curryArguments.reverse()) | ||
} | ||
} | ||
function curry(fnToCurry){ | ||
return (...curryArguments)=>{ | ||
const len = fnToCurry.length | ||
if(curryArguments[1]===undefined){ | ||
if(len > 1){ | ||
return (...futureArguments) => { | ||
if(len === 3 && futureArguments.length === 1){ | ||
return b => fnToCurry(curryArguments[0],futureArguments[0],b) | ||
} | ||
return fnToCurry(curryArguments[0],...futureArguments) | ||
} | ||
} | ||
}else if(curryArguments[2]===undefined && len === 3){ | ||
return (futureArgument) => fnToCurry(...curryArguments,futureArgument) | ||
} | ||
return fnToCurry(...curryArguments) | ||
} | ||
} | ||
exports.curry = curry | ||
exports.defaultTo = defaultTo | ||
exports.flip = flip | ||
exports.omitBy = omitBy | ||
exports.pickBy = pickBy | ||
exports.rangeBy = rangeBy | ||
exports.randomIndex = randomIndex | ||
exports.add = R.add | ||
@@ -93,2 +177,2 @@ exports.adjust = R.adjust | ||
exports.update = R.update | ||
exports.values = R.values | ||
exports.values = R.values |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88511
10
735
4
1