Posts

Showing posts with the label ecmascript-6

Does the ECMAScript specification allow Array to be “superclassable”?

Does the ECMAScript specification allow Array to be “superclassable”? I'm looking for any indications whether or not "superclassing" a builtin type will work according to the specification . That is, given any hypothetical conformant implementation of ECMAScript, does "superclassing" a builtin break the runtime by affecting the creation algorithm of the class constructor? "Superclassable" , a term I'm coining, refers to a class whose objects returned by constructing it, or calling it as a function if applicable, will be created with the same internal slots (except for [[Prototype]]), regardless of what its direct superclass is, as long as the initial [[Prototype]] of the class constructor and the class prototype are still in each respective inheritance chain after reassigning them. Consequently, in order to be "superclassable", a class must not call super() during creation. super() When "superclassing" an Array , I would expec...

Two arrays in a loop with JavaScript

Two arrays in a loop with JavaScript I have a problem in my script. I have two arrays, which is the data and also a month. What I want is that to append two merge the month in data, but then only 1 value shows in month, here is my code: const months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december']; ali_fcr.get().then((d) => { let store = ''; let getTotal = d.reduce(function(x, y) { return (x * 1) + (1 * y); }); let new_array = d.map((data) => { for (let i = 0; i < data.length; i++) { return '<td class="ta"><center><a class="ta" href="' + months[i] + '/ali">' + data + '</a></center></td>'; } }); new_array.unshift('<td>Case Receive</td>'); new_array.push('...

find duplicate obj properties and return lowest count property

find duplicate obj properties and return lowest count property Lets say I had an array that looked like: [ {count: 1, category: 4}, {count: 2, category: 4}, {count: 3, category: 2}, {count: 4, category: 2}, {count: 5, category: 8}, {count: 6, category: 8}, {count: 7, category: 1}, {count: 8, category: 1}, {count: 9, category: 1} {count: 10, category: 8}, ... ] What I want is to find the lowest count from each category and return a new array of objects. I could easily do this using a plain old loop i think, but would like to use map().reduce or some other new func technique. This should help stackoverflow.com/q/14446511/831878 – Ray Toal Jul 2 at 0:07 4 Answers 4 There are many ways to do it. One would be: function filterLowestCounts(a) { const lowestCo...

JavaScript - how to get value by using a JSON ID that is in another JSON

Image
JavaScript - how to get value by using a JSON ID that is in another JSON The exercise is as follows: It is required to obtain an Arrangement with the names of clients ordered from highest to lowest by the TOTAL sum of the balances. with these javascript objects: const clients = [ { id: 1, taxNumber: '86620855', name: 'HECTOR ACUÑA BOLAÑOS'}, { id: 2, taxNumber: '7317855K', name: 'JESUS RODRIGUEZ ALVAREZ'}, { id: 3, taxNumber: '73826497', name: 'ANDRES NADAL MOLINA'}, { id: 4, taxNumber: '88587715', name: 'SALVADOR ARNEDO MANRIQUEZ'}, { id: 5, taxNumber: '94020190', name: 'VICTOR MANUEL ROJAS LUCAS'}, { id: 6, taxNumber: '99804238', name: 'MOHAMED FERRE SAMPER' } ]; and: const accounts = [ { clientId: 6, bankId: 1, balance: 15000 }, { clientId: 1, bankId: 3, balance: 18000 }, { clientId: 5, bankId: 3, balance: 135000 }, { clientId: 2, bankId: 2, balance: 5600 }, { clientId: 3, bankId: 1, bala...

Regex to match all outermost pair of bracket into array

Regex to match all outermost pair of bracket into array I want a regex to match all outermost pair of bracket into array with their contents in them even if their content could be nested. This was my code this gives expected output console.log("52*((6*8)-4+3^(7+5))".match(/ *(([^]*)) */g)) /* => [ '((6*8)-4+3^(7+5))' ] correct*/ But this doesn't give expected output console.log("52*(6*8)-4+3^(7+5)".match(/ *(([^]*)) */g)) /* => [ '(6*8)-4+3^(7+5)' ] incorrect expected [ '(6*8)', '(7+5)' ]*/ please if anyone understand this problem help me /((.*)/)g try that. – Alex Jul 1 at 12:42 /((.*)/)g Apart from abusing regex features that elevate it above regular expressions, parsing nested brackets of unknown depth is impossible. – ASDFGert...