How to convert multidimensional array to this format - javascript

I have data coming in every second from a Web Socket eg
1- [["X",1],["Y",2],["Z",3]]
2 -[["X",2],["Y",7]]
3 -[["Y",5],["Z",1]]
4 -[["X",7]]
...
The resultant array for each iteration
1 - ["X",1,0],["Y",2,0],["Z",3,0]] // 0 is nothing but the difference it can also be + or minus
2 - ["X",2,1],["Y",7,5],["Z",3,0]] // diff from first iteration
3 - ["X",1,0],["Y",5,-2],["Z",1,-2]] // diff from second
the things i have tried till now
this.socketSubscription = this.socket.messages.subscribe((message) => {
this.prev = this.rows;
this.rows = JSON.parse(message);
if(this.prev){
this.rows.forEach(element => {
for (var index = 0; index < element.length; index++) {
console.log(element[index]);
let check = this.prev.find(prevElement => prevElement.find(el => el[0]));
console.log("check"+check);
/* if (element[0] === ())){
console.log("here");
} */
}
});
}

You don't need the for loop or a nested find. This is close enough and should get you on track:
var results;
function process(data) {
if (results) {
data.forEach(element => {
var key = element[0];
var val = element[1];
var index = results.findIndex(result => result[0] == key);
var prevVal = results[index][1];
var diff = val - prevVal;
results[index][1] = val;
results[index][2] = diff;
});
} else {
results = data.map(element => { element[2] = 0; return element; });
}
}
var a = [["X",1],["Y",2],["Z",3]];
var b = [["X",2],["Y",7]];
var c = [["Y",5],["Z",1]];
process(a); console.log(results); // [["X",1,0], ["Y",2, 0], ["Z",3, 0]]
process(b); console.log(results); // [["X",2,1], ["Y",7, 5], ["Z",3, 0]]
process(c); console.log(results); // [["X",2,0], ["Y",5,-2], ["Z",1,-2]]

Related

Get dates from array and disable those dates from calendar that repeat more than twice

I want to get dates from array which are repeated 3 times so I can disable those dates from calendar.
function disbaleDate() {
const arr = [
"1/6/2022",
"12/6/2022",
"4/6/2022",
"6/6/2022",
"1/6/2022",
"1/6/2022",
];
const increment = [];
for (let i = 1; i < arr.length; i++) {
for (let j = 0; j < i; j++) {
if (arr[j] === arr[i]) {
increment.push(arr[i]);
}
}
}
console.log(increment);
}
disbaleDate();
const disable = () => {
const arr = [
"1/6/2022",
"12/6/2022",
"4/6/2022",
"6/6/2022",
"1/6/2022",
"1/6/2022",
];
let data =[];
data = arr.filter((el, i) => i !== arr.indexOf(el) )
let result = data.filter((el,i) => i ===data.indexOf(el))
return result;
}
console.log(disable())
Ok, updating my answer
// reducer willproduce an object with the date as the key, and the amount repeated as the value
const countRepeated = arr.reduce((a, c) => {
if (a[c]) {
a[c] = a[c] + 1;
return a;
}
a[c] = 1;
return a;
}, {})
// will filter those whose values are greater than 2
return Object.keys(countRepeated).filter( date => date > 2)
function disableDate() {
const arr = ["1/6/2022", "12/6/2022", "4/6/2022", "6/6/2022", "1/6/2022", "1/6/2022",];
const backendData = ["12/12/2022", "12/6/2021", "14/6/2022", "16/6/2022", "1/6/2022", "11/6/2022",];
const increment = [];
if (backendData.length > 0) {
for (let i = 0; i < backendData.length; i++) {
if (arr.includes(backendData[i])) {
increment.push(backendData[i]);
}
}
}
console.log(increment);
}
disableDate();

JavaScript dual recursive call, how to pass back result?

I have one piece of JavaScript code which call recursive method twice, the result couldn't pass back:
var subSum = (nums, target) => {
var res = [];
var chosen = [];
subSets(nums, chosen, target, res);
return res;
};
var subSets = (nums, chosen, target, res) => {
if (nums.length === 0) {
if (sumAry(chosen) == target) {
console.log(array2Str(chosen));
res.push(chosen);
}
//console.log(array2Str(chosen));
} else {
let it = nums[0];
nums.shift();
chosen.push(it);
subSets(nums, chosen, target, res);
chosen.pop();
subSets(nums, chosen, target, res);
nums.unshift(it);
}
};
var array2Str = (ary) => {
if (!ary || ary.length < 1) return '';
let res = [];
arrayToStr(ary, res);
return res.join("");
};
var arrayToStr = (ary, res) => {
res.push('[');
for(let i = 0; i < ary.length; i ++) {
let it = ary[i];
if (Array.isArray(it)) {
arrayToStr(it, res);
if (i != ary.length - 1) {
res.push(', ');
}
} else {
res.push( (i == ary.length - 1) ? `${it}` : `${it}, `);
}
}
res.push(']');
};
The test code is:
let nums = [5,3,1,2,4,6];
console.log(`array2Str(subSum(nums, 7))`);
The output is:
Debugger attached.
[5, 2]
[3, 4]
[1, 2, 4]
[1, 6]
[[], [], [], []]
You can see the last line is the dump of the result array (res), and the content of 4 sub array are empty, but according the console log above, those values were pushed into the result array. anyway, if I comment out last subSets recursive call, the final result printing will not be empty.
Any idea on how to pass back the result with two recursive call? I tried one global array container and it didn't either.
the array is passing by reference , that's way is being overwriting .
use a primitive type like string , or shallow copy chosen array .
for this change the push line to this
res.push(chosen.slice()) // for shllow copy
res.push(chosen.join()) // for using primitive string
// i assume that the missing sumAry function shuld do ..
const sumAry = array => array.reduce((a, b) => a + b, 0)
var subSum = (nums, target) => {
var res = []
var chosen = []
subSets(nums, chosen, target, res)
return res
}
var subSets = (nums, chosen, target, res) => {
if (nums.length === 0) {
if (sumAry(chosen) == target) {
console.log(array2Str(chosen))
res.push(chosen.slice())
// res.push(chosen.join())
}
} else {
let it = nums[0]
nums.shift()
chosen.push(it)
subSets(nums, chosen, target, res)
chosen.pop()
subSets(nums, chosen, target, res)
nums.unshift(it)
}
}
var array2Str = ary => {
if (!ary || ary.length < 1) return ''
let res = []
arrayToStr(ary, res)
return res.join('')
}
var arrayToStr = (ary, res) => {
res.push('[')
for (let i = 0; i < ary.length; i++) {
let it = ary[i]
if (Array.isArray(it)) {
arrayToStr(it, res)
if (i != ary.length - 1) {
res.push(', ')
}
} else {
res.push(i == ary.length - 1 ? `${it}` : `${it}, `)
}
}
res.push(']')
}
let nums = [5, 3, 1, 2, 4, 6]
console.log(array2Str(subSum(nums, 7)))

How to find the most duplicate "values" in javascript array?

my question is actually similar to: Extracting the most duplicate value from an array in JavaScript (with jQuery)
I Found this but it always return one value only which is 200.
var arr = [100,100,200,200,200,300,300,300,400,400,400];
var counts = {}, max = 0, res;
for (var v in arr) {
counts[arr[v]] = (counts[arr[v]] || 0) + 1;
if (counts[arr[v]] > max) {
max = counts[arr[v]];
res = arr[v];
}
}
console.log(res + " occurs " + counts[res] + " times");
pls help me to return values not just one...
The result is should like this:
200,300,400
.
pls help thank you!
You have to iterate your counts to find the max occurred result.
var arr = [100,100,200,200,200,300,300,300,400,400,400];
var counts = {}, max = 0, res;
for (var v in arr) {
counts[arr[v]] = (counts[arr[v]] || 0) + 1;
if (counts[arr[v]] > max) {
max = counts[arr[v]];
res = arr[v];
}
}
var results = [];
for (var k in counts){
if (counts[k] == max){
//console.log(k + " occurs " + counts[k] + " times");
results.push(k);
}
}
console.log(results);
Create a Object iterating the arry containing the indexes of most repeated values, like below
var arr = [100,100,200,200,200,300,300,300,400,400,400];
valObj = {}, max_length = 0, rep_arr = [];
arr.forEach(function(el,i){
if(valObj.hasOwnProperty(el)){
valObj[el] += 1;
max_length = (valObj[el] > max_length) ? valObj[el] : max_length
}
else{
valObj[el] = 1;
}
});
Object.keys(valObj).forEach(function(val){
(valObj[val] >= max_length) && (rep_arr.push(val))
});
console.log(rep_arr);
After the object is created with key as array value and value as array indexes of that value, you can play/parse that. Hope this helps.
Iterating an array using for..in is not a good idea. Check this link for more information.
Hopefully below snippet will be useful
var arr = [100, 100, 200, 200, 200, 300, 300, 300, 400, 400, 400];
//Use a reduce fuction to create an object where 100,200,300
// will be keys and its value will the number of times it has
//repeated
var m = arr.reduce(function(i, v) {
if (i[v] === undefined) {
i[v] = 1
} else {
i[v] = i[v] + 1;
}
return i;
}, {});
// Now get the maximum value from that object,
//getMaxRepeated will be 3 in this case
var getMaxRepeated = Math.max(...Object.values(m));
//An array to hold elements which are repeated 'getMaxRepeated' times
var duplicateItems = [];
// now iterate that object and push the keys which are repeated
//getMaxRepeated times
for (var keys in m) {
if (m[keys] === getMaxRepeated) {
duplicateItems.push(keys)
}
}
console.log(duplicateItems)
The following would do the trick assuming that all items in arr are numbers:
//added some numbers assuming numbers are not sorted
var arr = [300,400,200,100,100,200,200,200,300,300,300,400,400,400];
var obj = arr.reduce(//reduce arr to object of: {"100":2,"200":4,"300":4,"400":4}
(o,key)=>{//key is 100,200, ... o is {"100":numberOfOccurrences,"200":numberOf...}
o[key] = (o[key])?o[key]+1:1;
return o;
},
{}
);
// obj is now: {"100":2,"200":4,"300":4,"400":4}
//create an array of [{key:100,occurs:2},{key:200,occurs:4}...
var sorted = Object.keys(obj).map(
key=>({key:parseInt(key),occurs:obj[key]})
)//sort the [{key:100,occurs:2},... by highest occurrences then lowest key
.sort(
(a,b)=>
(b.occurs-a.occurs===0)
? a.key - b.key
: b.occurs - a.occurs
);
console.log(
sorted.filter(//only the highest occurrences
item=>item.occurs===sorted[0].occurs
).map(//only the number; not the occurrences
item=>item.key
)
);
Try as following ==>
function getDuplicate( arr ){
let obj = {}, dup = [];
for(let i = 0, l = arr.length; i < l; i++){
let val = arr[i];
if( obj[val] /**[hasOwnProperty]*/ ) {
/**[is exists]*/
if(dup.find(a => a == val) ) continue;
/**[put Unique One]*/
dup.push(val);
continue;
};
/**[hold for further use]*/
obj[val] = true;
}
return dup;
};
Use ==>
getDuplicate([100,100,200,200,200,300,300,300,400,400,400]);
Try the following:
var candles = [100,100,200,200,200,300,300,300,400,400,400];
let tempArray = {}
for (let index = 0; index <= (candles.length - 1); index++) {
let valueToCompare = candles[index];
if (tempArray[valueToCompare]) {
tempArray[valueToCompare] = tempArray[valueToCompare] + 1;
} else {
tempArray[valueToCompare] = 1;
}
}
let highestValue;
Object.values(tempArray).forEach(item => {
if (highestValue === undefined) highestValue = item;
if (highestValue < item) highestValue = item;
});
console.log(highestValue);

Conditional from recursion returning undefined

My code will keep looping until the length of the customerTimeArray is zero.
When I console.log before the return line it outputs 10, which is the correct answer.
function Supermarket() {
this.customerTimeArray;
this.currentTillers = [];
this.runningTime = 0;
}
Supermarket.prototype.queueTime = function(customerTimeArray, numberOfTills) {
this.customerTimeArray = customerTimeArray;
if (customerTimeArray.length === 0) {
return this.runningTime;
}
this.currentTillers = this.customerTimeArray.splice(0, numberOfTills);
this.deductLowestToAll(this.currentTillers);
this.queueTime(this.customerTimeArray, numberOfTills);
};
Supermarket.prototype.deductLowestToAll = function(array) {
var newArray = [];
var lowest = Math.min.apply(null, array);
array.forEach(element => {
newArray.push(element - lowest);
if (element === lowest) {
this.runningTime += lowest;
newArray.pop(element);
}
});
this.currentTillers = newArray;
};
supermarket = new Supermarket();
supermarket.queueTime([1, 2, 3, 4], 1);

Get the index of a multidimensional array with the value of a given string in javascript

I have this array,
var arr = [["present",["John","Josh","Jay"]],["absent",["May","Mary","Mary Jane"]]];
var arr2 = [["J",["John","Josh","Jay"]],["M",["May","Mary","Mary Jane"]]];
And I want to get the data[0] of the array that have value of "Mary".
So in my example, value that I will get is "absent".
I want also to get the index of the array arr2 that have value of "Josh".
So in my second array, value that I will get is 0.
If possible to use underscore js, we can use it.
I tried to use _.contains() but failed.
Also these array is used in knockout js.
One other way of doing this job could be as follows;
var a1 = [["present",["John","Josh","Jay"]],["absent",["May","Mary","Mary Jane"]]],
a2 = [["J",["John","Josh","Jay"]],["M",["May","Mary","Mary Jane"]],["S",["Sally","Sam","Sammy Davis"]]],
getStatus = (a,n) => a.find(e => e[1].indexOf(n) !== -1)[0],
getIndex = (a,n) => a.findIndex(e => e[1].indexOf(n) !== -1);
console.log(getStatus(a1,"Mary"));
console.log(getIndex(a2,"Sammy Davis"));
var arr = [["present",["John","Josh","Jay"]],["absent",["May","Mary","Mary Jane"]]];
var arr2 = [["J",["John","Josh","Jay"]],["M",["May","Mary","Mary Jane"]]];
arr.forEach(function(e,i,a){
if(e[1].indexOf("Mary")>-1){
console.log(e[0])
}
});
arr2.forEach(function(e,i,a){
if(e[1].indexOf("Josh")>-1){
console.log(e[0])
}
});
First using filter() and second findIndex()
var arr = [["present",["John","Josh","Jay"]],["absent",["May","Mary","Mary Jane"]]];
var result1 = arr.filter(x => x[1].indexOf("Mary") !== -1)[0][0];
console.log(result1); // absent
var arr2 = [["J",["John","Josh","Jay"]],["M",["May","Mary","Mary Jane"]]];
var result2 = arr.findIndex(x => x[1].indexOf("Josh") !== -1);
console.log(result2); // 0
If your data set isn't really huge you can store two map objects in memory to quickly access values. Note that this won't work for duplicate names.
The benefit of this approach is that you only have to loop through each array once. If you use any method based on indexOf, you'll loop through your data every time you retrieve a value.
var arr = [["present",["John","Josh","Jay"]],["absent",["May","Mary","Mary Jane"]]];
var arr2 = [["J",["John","Josh","Jay"]],["M",["May","Mary","Mary Jane"]]];
var makeKeyMap = function(arr) {
return arr.reduce(function(map, data) {
data[1].forEach(function(key) {
map[key] = data[0];
});
return map;
}, {});
};
var makeIndexMap = function(arr) {
return arr.reduce(function(map, data, index) {
data[1].forEach(function(key) {
map[key] = index;
});
return map;
}, {});
};
var arrMap = makeKeyMap(arr);
var arr2Map = makeIndexMap(arr2);
console.log(arrMap["Mary"]);
console.log(arr2Map["Josh"]);
Edit: a performance test
var myTestData = createTestData();
var randomNameToFind = (function() {
var namesToFind = ["Aileen","Christina","Donna","Judith","Mandy","Sandra","Dawn","Tracey","Mhairi","Victoria","Carolyn","Gayle","Maria","Valerie"];
return function() {
return namesToFind[Math.floor(Math.random() * namesToFind.length)];
}
}());
console.log("Finding the number index for a random name out of 800 names, 10000 times:");
console.time("using index of approach");
var usingIndexOf = (a,n) => a.findIndex(e => e[1].indexOf(n) !== -1);
var results = [];
for (var i = 0; i < 10000; i += 1) {
results.push(usingIndexOf(myTestData, randomNameToFind()));
}
console.timeEnd("using index of approach");
console.time("using map approach");
var makeIndexMap = function(arr) {
return arr.reduce(function(map, data, index) {
data[1].forEach(function(key) {
map[key] = index;
});
return map;
}, {});
};
var myMap = makeIndexMap(myTestData);
results = [];
for (var j = 0; j < 10000; j += 1) {
results.push(myMap[randomNameToFind()]);
}
console.timeEnd("using map approach");
console.log("index map size: " + sizeof(myMap) + " bytes");
// Random data generation code below
function createTestData() {
var names = ["Nicola","Karen","Fiona","Susan","Claire","Sharon","Angela","Gillian","Julie","Michelle","Jacqueline","Amanda","Tracy","Louise","Jennifer","Alison","Sarah","Donna","Caroline","Elaine","Lynn","Margaret","Elizabeth","Lesley","Deborah","Pauline","Lorraine","Laura","Lisa","Tracey","Carol","Linda","Lorna","Catherine","Wendy","Lynne","Yvonne","Pamela","Kirsty","Jane","Emma","Joanne","Heather","Suzanne","Anne","Diane","Helen","Victoria","Dawn","Mary","Samantha","Marie","Kerry","Ann","Hazel","Christine","Gail","Andrea","Clare","Sandra","Shona","Kathleen","Paula","Shirley","Denise","Melanie","Patricia","Audrey","Ruth","Jill","Lee","Leigh","Catriona","Rachel","Morag","Kirsten","Kirsteen","Katrina","Joanna","Lynsey","Cheryl","Debbie","Maureen","Janet","Aileen","Arlene","Zoe","Lindsay","Stephanie","Judith","Mandy","Jillian","Mhairi","Barbara","Carolyn","Gayle","Maria","Valerie","Christina","Marion","Nicola","Karen","Susan","Claire","Fiona","Angela","Sharon","Gillian","Julie","Jennifer","Michelle","Louise","Lisa","Amanda","Donna","Tracy","Alison","Elaine","Jacqueline","Sarah","Caroline","Elizabeth","Laura","Lynn","Deborah","Lesley","Margaret","Joanne","Pauline","Lorraine","Carol","Kirsty","Yvonne","Lorna","Emma","Lynne","Tracey","Heather","Catherine","Pamela","Helen","Linda","Jane","Anne","Kerry","Suzanne","Wendy","Victoria","Diane","Mary","Dawn","Clare","Gail","Paula","Ann","Shona","Hazel","Christine","Andrea","Samantha","Marie","Lynsey","Sandra","Denise","Lee","Kelly","Gayle","Debbie","Jill","Kathleen","Patricia","Joanna","Catriona","Shirley","Ruth","Zoe","Leigh","Rachel","Melanie","Kirsteen","Aileen","Christina","Janet","Katrina","Stephanie","Audrey","Kirsten","Arlene","Maureen","Morag","Marion","Mhairi","Allison","Cheryl","Maria","Kim","Anna","Lindsay","Rebecca","Katherine","Mandy","Nicola","Karen","Claire","Angela","Fiona","Susan","Jennifer","Julie","Gillian","Michelle","Sharon","Sarah","Louise","Donna","Laura","Amanda","Alison","Lisa","Caroline","Kirsty","Jacqueline","Elaine","Lesley","Lynn","Deborah","Elizabeth","Joanne","Emma","Tracy","Lorraine","Lynne","Margaret","Heather","Carol","Lorna","Pauline","Kelly","Helen","Catherine","Linda","Victoria","Suzanne","Kerry","Pamela","Lee","Wendy","Jane","Yvonne","Tracey","Anne","Clare","Mary","Diane","Christine","Lynsey","Samantha","Shona","Andrea","Marie","Gail","Melanie","Dawn","Ann","Paula","Jill","Ruth","Leigh","Hazel","Debbie","Joanna","Denise","Lindsay","Gayle","Patricia","Catriona","Kathleen","Sandra","Leanne","Stephanie","Rachel","Katrina","Shirley","Kirsteen","Janet","Arlene","Zoe","Jillian","Anna","Judith","Mhairi","Natalie","Audrey","Carolyn","Morag","Aileen","Cheryl","Rebecca","Allison","Barbara","Mandy","Claire","Nicola","Karen","Angela","Gillian","Fiona","Jennifer","Laura","Susan","Julie","Michelle","Lisa","Sharon","Louise","Sarah","Tracy","Donna","Kelly","Kirsty","Amanda","Alison","Joanne","Caroline","Emma","Jacqueline","Elaine","Elizabeth","Lynne","Lesley","Deborah","Kerry","Victoria","Carol","Catherine","Lynn","Pauline","Margaret","Lorna","Lynsey","Lorraine","Linda","Suzanne","Tracey","Heather","Yvonne","Jane","Dawn","Mary","Helen","Anne","Wendy","Lee","Pamela","Jill","Lindsay","Clare","Christine","Diane","Leigh","Samantha","Shona","Joanna","Ruth","Debbie","Gail","Marie","Andrea","Paula","Kathleen","Catriona","Katrina","Denise","Melanie","Ann","Sandra","Gayle","Hazel","Jillian","Stephanie","Rachel","Kim","Natalie","Katherine","Patricia","Leanne","Cheryl","Mhairi","Morag","Arlene","Zoe","Kathryn","Aileen","Ashley","Judith","Anna","Frances","Janet","Lucy","Vicky","Christina","Kirsten","Rebecca","Nicola","Claire","Laura","Karen","Michelle","Louise","Jennifer","Fiona","Lisa","Gillian","Angela","Julie","Susan","Sarah","Kelly","Donna","Sharon","Emma","Caroline","Alison","Joanne","Tracy","Kirsty","Lynne","Amanda","Elaine","Jacqueline","Lesley","Kerry","Elizabeth","Lynn","Margaret","Deborah","Catherine","Heather","Lorna","Yvonne","Carol","Lorraine","Suzanne","Lynsey","Victoria","Helen","Linda","Pauline","Dawn","Anne","Jane","Tracey","Clare","Mary","Diane","Jill","Denise","Lee","Leanne","Christine","Shona","Pamela","Samantha","Paula","Joanna","Debbie","Stacey","Hazel","Cheryl","Lindsay","Gail","Rachel","Marie","Ann","Catriona","Andrea","Ruth","Kathryn","Katrina","Mhairi","Wendy","Leigh","Gayle","Melanie","Sandra","Stephanie","Anna","Jillian","Amy","Carolyn","Patricia","Carrie","Natalie","Kathleen","Lyndsey","Ashley","Rebecca","Vicky","Christina","Lindsey","Katherine","Arlene","Sara","Laura","Claire","Nicola","Lisa","Louise","Michelle","Fiona","Karen","Gillian","Jennifer","Emma","Angela","Susan","Kelly","Julie","Donna","Sarah","Kirsty","Sharon","Joanne","Amanda","Tracy","Alison","Elizabeth","Caroline","Elaine","Jacqueline","Lynne","Leanne","Deborah","Lesley","Lorraine","Victoria","Lynn","Pamela","Kerry","Lynsey","Lorna","Carol","Margaret","Heather","Helen","Catherine","Suzanne","Tracey","Yvonne","Cheryl","Linda","Pauline","Debbie","Jane","Dawn","Clare","Lindsay","Mary","Shona","Anne","Rachel","Jill","Christine","Natalie","Samantha","Diane","Lee","Wendy","Joanna","Paula","Marie","Ann","Denise","Catriona","Gayle","Hazel","Kathleen","Stacey","Gail","Ashley","Andrea","Ruth","Anna","Jillian","Leigh","Katrina","Stephanie","Mhairi","Katherine","Sandra","Lyndsey","Christina","Lucy","Patricia","Carrie","Rebecca","Kathryn","Lyndsay","Melanie","Amy","Sara","Arlene","Kirsten","Laura","Claire","Lisa","Nicola","Louise","Karen","Fiona","Jennifer","Michelle","Emma","Sarah","Gillian","Kelly","Susan","Angela","Donna","Kirsty","Julie","Pamela","Joanne","Caroline","Amanda","Tracy","Sharon","Lynne","Elaine","Deborah","Jacqueline","Alison","Lynsey","Victoria","Kerry","Leanne","Lorraine","Lesley","Elizabeth","Lorna","Catherine","Lynn","Suzanne","Heather","Helen","Lindsay","Margaret","Clare","Cheryl","Debbie","Pauline","Dawn","Carol","Mary","Natalie","Linda","Jane","Diane","Stacey","Carrie","Yvonne","Rebecca","Christine","Marie","Charlene","Rachel","Anne","Tracey","Jill","Samantha","Ashley","Paula","Joanna","Stephanie","Andrea","Shona","Denise","Anna","Hazel","Katrina","Ruth","Gayle","Lee","Sara","Catriona","Kathryn","Leigh","Mhairi","Wendy","Amy","Jillian","Katherine","Gail","Linsey","Christina","Lucy","Melanie","Sandra","Ann","Kathleen","Shelley","Kirsten","Kim","Lyndsey","Laura","Claire","Lisa","Nicola","Emma","Louise","Jennifer","Michelle","Sarah","Fiona","Karen","Gillian","Kirsty","Donna","Kelly","Pamela","Susan","Julie","Angela","Amanda","Lynsey","Sharon","Lynne","Deborah","Joanne","Victoria","Caroline","Alison","Leanne","Gemma","Elaine","Jacqueline","Lesley","Elizabeth","Lorraine","Kerry","Heather","Debbie","Catherine","Lynn","Lorna","Tracy","Suzanne","Yvonne","Cheryl","Natalie","Margaret","Lindsay","Diane","Helen","Pauline","Ashley","Rachel","Clare","Carol","Christine","Linda","Dawn","Rebecca","Stephanie","Jill","Tracey","Jane","Stacey","Paula","Shona","Anna","Charlene","Anne","Marie","Catriona","Samantha","Joanna","Ruth","Andrea","Mary","Denise","Kim","Mhairi","Hazel","Lauren","Amy","Kathryn","Carrie","Lyndsey","Lucy","Gail","Katherine","Christina","Linsey","Wendy","Katrina","Kimberley","Ann","Lee"];
var nameMap = names.reduce((map, n) => {
map[n[0]] = map[n[0]] || [];
map[n[0]].push(n);
return map;
}, {});
var testData = Object.keys(nameMap)
.sort()
.reduce((res, k) => {
res.push([k, nameMap[k]]);
return res;
}, []);
return testData;
};
<script src="http://code.stephenmorley.org/javascript/finding-the-memory-usage-of-objects/sizeof.compressed.js"></script>

Categories

Resources