Skip to content

Instantly share code, notes, and snippets.

View mgmgpyaesonewin's full-sized avatar
🐒
coding

Pyae Sone Win mgmgpyaesonewin

🐒
coding
View GitHub Profile
@mgmgpyaesonewin
mgmgpyaesonewin / flattern.js
Created April 24, 2018 02:17
Flattern JS Array
let res = [ [ 8, 5, 11 ], [ 6, 3, 9 ] ]
res = [].concat(...res);
return res;
// output -> [ 8, 5, 11, 6, 3, 9 ]
@mgmgpyaesonewin
mgmgpyaesonewin / sum.js
Last active May 9, 2018 07:42
Finding the total number of item in a array
sum: function(arr) {
return arr.reduce( (total, num) => total + num, 0);
}
@mgmgpyaesonewin
mgmgpyaesonewin / number_format.js
Created June 6, 2018 04:39
1000 => 1,000; 1000000 => 1,000,000
function number_with_commas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
let a = Object.create(null); // => {}
let a = {}; // => {}
var arr = [3, 5, 7];
arr.foo = 'hello';
for (var i in arr) {
console.log(i); // logs "0", "1", "2", "foo"
}
for (var i of arr) {
console.log(i); // logs 3, 5, 7
}
let arr = ['label one', 1, 'label two', 2, 'label 3', 3];
arr.chunk(2)
.map(([label, value]) => ({ label, value }));
Object.defineProperty(Array.prototype, 'chunk', {
value: function(n) {
// ACTUAL CODE FOR CHUNKING ARRAY:
return Array.range(Math.ceil(this.length/n)).map((x,i) => this.slice(i*n,i*n+n));
}
});
@mgmgpyaesonewin
mgmgpyaesonewin / Reduce_array_to_objects.js
Created September 17, 2018 11:01
Reduce_array_to_objects
_.reduce(code, function(memo, current) { return _.assign(memo, current) }, {})
@mgmgpyaesonewin
mgmgpyaesonewin / codeGeratorFrom1to100.js
Created September 18, 2018 08:16
codeGeratorFrom1to100 using randomstring package
for (var i=0;i<100;i++) {
let generated = window.randomstring.generate(4);
code.push({
[`R${generated}`] : {
used: false,
[`R${generated}A`] : {
used: false,
},
[`R${generated}B`] : {
used: false,
@mgmgpyaesonewin
mgmgpyaesonewin / register.vue
Created September 24, 2018 05:08
Firebase auth verify phone with email/password
<template>
<div>
<v-container align-content-center>
<v-layout class="px-4 pt-4 pt-2">
<v-flex>
<v-form v-model="valid">
<div class="py-1">
<v-text-field
v-model="name"
:rules="nameRules"