Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

switching light bulbs problem javascript

function bulbs(arr){
  var switched = 0;
    for(var i = 0; i < arr.length; i++){
      var initial = arr[i] === 1,
          current = (switched % 2 === 1)? !initial:initial;
      if(current === false){
        switched++;
      }
    }
  return switched;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native ios accessibility font size 
Javascript :: Gamification Details Component is not declared in any Angular module 
Javascript :: how to install ghost js 
Javascript :: testing code through local server using express.js 
Javascript :: javascript cookies all together 
Javascript :: how to chaage background color of any element from java script 
Javascript :: wait for element to be loaded 
Javascript :: 1st element in underscore javascript 
Javascript :: maptable elo 
Javascript :: auto load in element show 
Javascript :: Download A File With Link Using ExpressJS 
Javascript :: mdn javascript array 
Javascript :: The JavaScript call() Method 
Javascript :: Inside Fetch Is A Request 
Javascript :: ahead-of-time (AOT) compilation 
Javascript :: how to store new object made by constructor classes data in local storage using javascript 
Javascript :: Backbone View Template 
Javascript :: How to Loop Through an Array with a for…of Loop in JavaScript 
Javascript :: recursive function and json object 
Javascript :: Backbone Router Notes 
Javascript :: chart cdn js 
Javascript :: remove duplicate node 
Javascript :: jsdoc default value 
Javascript :: ampscript remove special character 
Javascript :: moment add 
Javascript :: js array map concat 
Javascript :: yarn react 
Javascript :: how to reverse sort lines in javascript 
Javascript :: optional css tippy 
Javascript :: JavaScript Add Methods to a Constructor Function Using Prototype 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =