Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
JS - check 2 arrays, add 1 or 2, logical operations
//nodejs v4.2.6 http://rextester.com/KXIU83587 empNum = (data1, data2) => { var activeArr = []; var activeOnes = 0; for (var i=0; i<data1.length; i++) { activeArr.push(data1[i]&&data2[i] ? 2 : 1) } return activeArr; // [1, 2 ] < -- This is not what I need. } // Test 1 var array1= [5, 6, 44, 2, 6]; var array2 = ['', '', '', 5, 7]; console.log(empNum(array1, array2)); //[ 1, 1, 1, 2, 2 ] // Test 2 console.log(empNum( [5, 0, 44, 2, 6], [8, 7, undefined, 5, 7,] )); // [ 2, 1, 1, 2, 2 ] // Test 3 console.log(empNum( ["JavaScript", 0, undefined, null, 6], [8, 7, undefined, 5, 7,] )); // [ 2, 1, 1, 1, 2 ] // Test 4 console.log(empNum( [0, 0, 44, 2, "Python"], [8, 7, undefined, 5, 7,] )); // [ 1, 1, 1, 2, 2 ]
run
|
edit
|
history
|
help
0
Accept matching keys in object
Union of two sorted arrays
Holyboi
Rest Params
JSON parse
Find the missing number in array
Lowertoupper
example for node promises
demo.js
Tree Structure