Schimming that’s perfect.

Kenndy: I think we don’t lose reausability with that

Kenndy: Well, anyway I’m still experimenting

Kenndy: Right now it feels simpler and yet as powerful

Riska: Yeah seems that way to me too

Riska: It’s reusable because you’re putting each step into a function, similar to how you would write a function with Cu***ber to match some phrase

Riska: Similarly it keeps the test easy to read as the test function describes a step, rather than the often very complex implementation for an e2e test

Kenndy: There are complex implementation details, but encapsulated, this is what bothers me

Kenndy: I don’t want my tests to broke after some trivial changes

Kenndy: Or I should say, not changes but refactor

Kenndy: Behaviour stays the same

Splain: Hey guys, I’m looking for a basic utility that I know is out there but I don’t know what it’s called. I have a bunch of numbers for example, ranging from 324 to 188,012. I’d like to give each number a value of 0-100 based on where it falls in the stack

Vilca: Ie in that case, 324 would be 0, 188,012 would be 100, and whatever falls in between would round to the nearest number between 1-99

Tutino: What is that logic called so I can google it?

Kenndy: Timwis: I think “normalized range”

Dimare: Interesting Kenndy. And if I wanted there to only be 5 breaks between 0 and 100? ie they fall into the “0, 20, 40, 60, 80, or 100 bucket”?

Theis: Https:// perfect! thanks!

Lyssy: Hm, still need to figure out which step each value falls into

Pappan: I see I can get an array of possible steps

Kenndy: Tell me what input you have

Kenndy: And what uotput you want

Riska: Kenndy: yeah that’s what I mean, the test itself is easy to understand because the detail that’s not relevant to the reader of the test is in the function

Duperclay: Well i have geojson, which I’ll iterate through, giving me an object of properties. One of those properties is the “value”. I’d like to feed that into this “color picker”, which I’ve already given the min & max and a list of colors to

Battistini: In fact, I’ll probably use TinyColor to give it *one* color and use the range/step to *darken* the color

Verville: So on initializing this little util, I imagine I’ll p*** it the min, max, and number of steps.

Poter: Then for each object in the array, I’ll p*** the initialized util the value and get back whatever step it falls on

Saltz: Yes, i think that would be ideal

Kenndy: I need concrete example

Kenndy: Like: input=0, 10, step=2 = 0, 2, 4, 6, 8

Riska: Btw, I have a new article on Sitepoint. Promises in JS unit tests: the definitive guide

Cotugno: Timwis: are you after a colour picker that ends up giving a rbg?

Sleger: Min: 324, max: 188012 – I have a number, 1000, and I want to know where between 0 and 100 it falls in that min/max range

Meluso: Guessx: if you know of one that does that, it may be a shortcut, sure

Mylar: Yea i made/modded one a while back

Roorda: I’m having a tiny issue with this being rebound by

Kaak: See,console 10 LoC

Mandel: I had to introduce a var thiz = this before using map, is there a better way ?

Schimming: Function min, max, needle { return needle/max – min*100; }324, 188012, 1000

Wakley: Schimming: number 0.5327991134222753

Riska: Python476: the second parameter to map is the this-context it will use

Riska: So you can do ctx.a.mapfunc, ctx

Azimi: Zomg: aight, gonna try

Cull: Timwis:

Mcmahon: Schimming that’s perfect and quite clever. thank you