Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Enter "hello" ( hello )

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Enter "hello" ( hello )

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Enter "hello" ( hello )

Have an account? Sign In Now

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the question so it can be answered easily.

Please choose the appropriate section so the question can be searched easily.

Please choose suitable Keywords Ex: question, poll.

Browse
Type the description thoroughly and in details.

Choose from here the video type.

Put Video ID here: https://www.youtube.com/watch?v=sdUUx5FdySs Ex: "sdUUx5FdySs".

Enter "hello" ( hello )

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

IT Community and Answers

IT Community and Answers Logo IT Community and Answers Logo

IT Community and Answers Navigation

Search
Ask A Question

Mobile menu

Close
Ask a Question
You can use WP menu builder to build menus
Home/ Questions/Q 4309
Next
Closed
Anonymous
Anonymous
Asked: August 16, 20212021-08-16T18:23:50+00:00 2021-08-16T18:23:50+00:00In: Codewars solutions and discussions

Logical calculator Codewars JS 8 kyu

https://www.codewars.com/kata/57096af70dad013aa200007b/train/javascript

Your Task

Given an array of Boolean values and a logical operator, return a Boolean result based on sequentially applying the operator to the values in the array.

Examples

  1. booleans = [True, True, False], operator = "AND"
  • True AND True -> True
  • True AND False -> False
  • return False
  1. booleans = [True, True, False], operator = "OR"
  • True OR True -> True
  • True OR False -> True
  • return True
  1. booleans = [True, True, False], operator = "XOR"
  • True XOR True -> False
  • False XOR False -> False
  • return False

Input

  1. an array of Boolean values (1 <= array_length <= 50)
  2. a string specifying a logical operator: "AND", "OR", "XOR"

Output

A Boolean value (True or False).

Related Questions and Answers:

  • Regexp Basics - is it a digit? js codewars
  • Crash Override codewars js
  • Basic Training: Add item to an Array.js
  • Job Matching #1 codewars js 8 kyu
  • Welcome codewars javascript 8 kyu
codewarsjs
  • 0
  • 2 2 Answers
  • 559 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    john_t Enlightened
    2021-08-16T18:29:19+00:00Added an answer on August 16, 2021 at 6:29 pm
    Logical calculator Codewars JS 8 kyu

    function logicalCalc(array, op) {
    var result = array[0];
    for(var i = 1; i < array.length; i++) {
    if(op == "AND") {
    result = result && array[i];
    }
    if(op == "OR") {
    result = result || array[i];
    }
    if(op == "XOR") {
    result = result != array[i];
    }
    }
    return result;
    }

    • 1
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. john_t Enlightened
    2021-08-16T18:24:17+00:00Added an answer on August 16, 2021 at 6:24 pm

    const operations = {
    AND: (a, b) => a && b,
    OR: (a, b) => a || b,
    XOR: (a, b) => a !== b,
    }

    const logicalCalc = (array, op) => array.reduce(operations[op])

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sorry this question is closed.

Sidebar

Ask A Question

Stats

  • Questions 778
  • Answers 10
  • Best Answers 8
  • Users 2
  • Popular
  • Answers
  • Anonymous

    Logical calculator Codewars JS 8 kyu

    • 2 Answers
  • Anonymous

    Reversed sequence javascript codewars 8 kyu

    • 2 Answers
  • john_t

    Are arrow functions odd?.js

    • 1 Answer
  • john_t
    john_t added an answer function odds(values){ return values.filter(values => values % 2 != 0);… September 12, 2021 at 6:29 pm
  • john_t
    john_t added an answer function toCsvText(array) { return array.join('\n'); } https://www.codewars.com/kata/5a34af40e1ce0eb1f5000036/train/javascript September 12, 2021 at 6:20 pm
  • john_t
    john_t added an answer function solution(a, b){ return a.length < b.length ? a +… September 7, 2021 at 8:04 pm

Related Questions

  • Anonymous

    Short Long Short codewars js

    • 1 Answer
  • john_t

    Fuel Calculator.js

    • 0 Answers
  • john_t

    Freudian translator.js

    • 0 Answers

Top Members

john_t

john_t

  • 774 Questions
  • 55k Points
Enlightened
Jacob

Jacob

  • 1 Question
  • 21 Points
Begginer

Trending Tags

codewars codewars js 8 kyu codewars kata codewars kata solution codewars solutions data studio ga individual qualification exam answers google ads Google Analytics Individual Qualification google analytics individual qualification exam answers javascript js Segment Conversion Type Name

Explore

  • Questions
    • New Questions

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.