Git Product home page Git Product logo

codewars's Introduction

CodeWars

A compilation of CodeWars Challenges in JavaScript

Is this a triangle?

Implement a method that accepst 3 integer values a, b, c. The method should return true if a triangle can be built with the sides of a given length and false in any other case. (In this case, all triangles must have surface greater than 0 to be accepted).

function isTrianlge(a, b, c){ 
  let max = Math.max(a,b,c); 
  let sum = a + b + c; 
  return sum - max > max; 
  } 

Additional solution I really liked:

function isTriangle(a. b.c){ 
 return a + b > c && a + c > b && c + b > a; 
 } 

Square Every Digit

Welcome. In this kata, you are asked to square every digit of a number. For example, if we run 9119 through the function, 811181 will come out. Note: The function accepts an integer and returns an integer.

function squareDigits(num){
  var num1 = num.toString(); 
  var num2 = num1.split(""); 
  var result = ' ';
  for (var i = 0; i < num2.length; i++) { 
  result += Math.pow( num2[i], 2); 
  }; 
  var test = parseInt(result); 

return test;
}

Additional solution I really liked:

function squareDigits(num){ 
var array = num.toString().split('').map(function(int) { 
  var i = parseInt(int); 
  return i * i; 
  }); 
  return parseInt(array.join("")); 
  }  

A square of squares

You like building blocks. You especially like building blocks that are squares. And what you even like more, is to arrange them into a square of square building blocks!

However, sometimes, you can't arrange them into a square. Instead, you end up with an ordinary rectangle! Those blasted things! If you just had a way to know, whether you're currently working in vain… Wait! That's it! You just have to check if your number of building blocks is a perfect square.

Task

Given an integral number, determine if it's a square number:

In mathematics, a square number or perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. The tests will always use some integral number, so don't worry about that in dynamic typed languages.

var isSquare = function(n){ 
	var number = n; 
  return(Math.sqrt(number)) % 1 === 0; 
  } 

Additional solution I really liked:

var isSquare = function(n){ 
	if(Math.sqrt(n) % 1) == 0) 
   return true; 
   else 
   return false; 
   } 

codewars's People

Contributors

cj87holler avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.