Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to save console.count() as an integer?

I am trying to divide 1 by the console.count() every time it is used. However, this code does not work.

   var counter = console.count();
    console.log(1/counter);

Any suggestions on how I could do this? I tried doing parseInt but no luck.

like image 749
kennysong Avatar asked May 31 '26 11:05

kennysong


1 Answers

Way to save console.count() as an integer?

No. console.count() does not return anything, it directly prints to the console, just like console.log().


Simple implementation of console.count:

var count = (function() {
  var counter = {};
  return function(v) {
    return (counter[v] = (counter[v] || 0) + 1);
  }
}());

console.log('foo', count('foo'));
console.log('foo', count('foo'));
console.log('bar', count('bar'));
      
like image 164
Felix Kling Avatar answered Jun 03 '26 01:06

Felix Kling