Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
JS - check 2 arrays, add 1 or 2, logical operations
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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 ]
[
+
]
Show input
Absolute running time: 0.14 sec, cpu time: 0.1 sec, memory peak: 15 Mb, absolute service time: 0,14 sec
edit mode
|
history
|
discussion
[ 1, 1, 1, 2, 2 ] [ 2, 1, 1, 2, 2 ] [ 2, 1, 1, 1, 2 ] [ 1, 1, 1, 2, 2 ]