Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Counting Sheep

//Consider an array/list of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).

/* For example,
  [true,  true,  true,  false,
  true,  true,  true,  true ,
  true,  false, true,  false,
  true,  false, false, true ,
  true,  true,  true,  true ,
  false, false, true,  true]
*/
// The correct answer would be 17.

function countSheeps(arrayOfSheep) {
  let numberOfSheep = 0
  arrayOfSheep.forEach(sheep => sheep ? numberOfSheep++ : false)
  return numberOfSheep
}

// With love @kouqhar
Comment

PREVIOUS NEXT
Code Example
Javascript :: Expected an identifier and instead saw ' 
Javascript :: require express server.js 
Javascript :: javascript substring 
Javascript :: node red debug to console 
Javascript :: Using fetch to upload files 
Javascript :: how to delete everything from a folder in js 
Javascript :: javascript regex grouping replace 
Javascript :: apollo client nextjs 
Javascript :: react chunk file too large 
Javascript :: create or update in sequelize 
Javascript :: math js 
Javascript :: jquery slide 
Javascript :: Javascript Event Loop 
Javascript :: update to node 15.11 
Javascript :: Error: ENOENT: no such file or directory, lstat ode_modules@react-navigationcoresrcgetStateFromPath.tsx 
Javascript :: js if not undefined or null 
Javascript :: react-data-table-component cell action stack overflow 
Javascript :: javascript shift 
Javascript :: javascript function 
Javascript :: react barcode scanner 
Javascript :: vanilla js http server 
Javascript :: js compare objects 
Javascript :: how to add the click event into two element in jquery 
Javascript :: bootstrap modal close on form submit in react 
Javascript :: counter javascript 
Javascript :: how to upload file with button react 
Javascript :: leaflet marker 
Javascript :: document.getanimation 
Javascript :: react native select option 
Javascript :: Reactjs function exemple useEffect 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =