Skip to content

Instantly share code, notes, and snippets.

🐥
🐔🐔🥚🥚

bitfish bitfishxyz

🐥
🐔🐔🥚🥚
Block or report user

Report or block bitfishxyz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View count.js
function countFrequency(arr) {
return arr.reduce(function(result, ele){
// Judge whether this element has been counted before
if (result.get(ele) != undefined) {
/**
* If this element has been counted before,
* increase the frequency of its occurrence by 1
*/
result.set(ele, result.get(ele) + 1)
} else {
View result.js
let arr = [1,2,35,33,5,3,3,23,5,6,1,44,33,6];
let resultMap = arr.reduce(function(result, ele){
if (ele in result) {
result[ele]++;
} else {
result[ele] = 1;
}
return result;
}, {});
View count.js
function count(arr){
let result = new Map();
for(let ele of arr){
if (result.get(ele) == undefined) {
result.set(ele, 1);
} else {
result.set(ele, result.get(ele) + 1);
}
}
return result;
View count.js
function count(arr, targetValue){
let count = 0;
for(let ele of arr){
if (ele === targetValue) {
count++;
}
}
return count
}
View max.js
function max(arr){
let max = arr[0];
for (let ele of arr) {
if(ele > max) {
max = ele;
}
}
return max;
}
View max
function max(arr){
let max = arr[0];
for (let ele of arr) {
if(ele > max) {
max = ele;
}
}
return max;
}
View isNative.js
function isNative (Ctor){
return typeof Ctor === 'function' && /native code/.test(Ctor.toString())
}
View browser.js
const inBrowser = typeof window !== 'undefined'
// get user agent
const UA = inBrowser && window.navigator.userAgent.toLowerCase()
// detect browser
const isIE = UA && /msie|trident/.test(UA)
const isIE9 = UA && UA.indexOf('msie 9.0') > 0
const isEdge = UA && UA.indexOf('edge/') > 0
const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge
View closure.js
var list = document.getElementsByTagName('li');
for (var i = 0; i < list.length; i++) {
list[i].addEventListener('click', function(i){
return function(){
alert(i + 1)
}
}(i), true)
}
View a.js
var list = document.getElementsByTagName('li');
for (var i = 0; i < list.length; i++) {
list[i].addEventListener('click', function(){
alert(i + 1)
}, true)
}
You can’t perform that action at this time.