This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solutions.js
113 lines (83 loc) · 2.82 KB
/
solutions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"use strict";
/**
* Write your solutions here.
*
* **Note**: While normally it is good practice to wrap your javascript in an
* immediately invoked function expression (iife), you should _not_ do that
* here. If you do, the automated tests will not be able to see your functions.
* If you don't know what an iffe is, don't worry about it :)
*
* This file is for defining the following functions. See README.md for more detail.
* isTrue
* isFalse
* not
* addOne
* isEven
* isIdentical
* isEqual
* or
* and
* concat
*/
// 1. isTrue
// Define a function named `isTrue` that takes in any input and returns true if
// the input provided is exactly equal to `true` in value and data type.
function isTrue(x) {
return x === true;
}
// 2. isFalse
// Define a function named `isFalse` that takes in a value and returns a true if
// and only if the provided input is equal to false in both type and value.
function isFalse(x) {
return x === false;
}
// 3. not
// Define a function named `not` that takes in any input and returns the boolean opposite of the provided input.
function not(x) {
return x = !x // ! is used to reflect "not"
}
// 4. addOne
// Define a function named `addOne` that takes in a single input.
// If the input is a number or a numeric string, return the value plus one.
function addOne(x) {
return x = x + 1
}
// 5. isEven
// Define a function named `isEven` that takes in a single input.
// If the input is an even number or a string containing an even number, return `true`.
// Any other input should return false for the output.
function isEven(x) {
return (parseFloat(x) % 2 == 0) // parsFloat passes a string
}
// 6. isIdentical
// Define a function named `isIdentical` that takes in two input arguments.
// If each input is equal both in data type and in value, then return `true`.
// If the values are not the same data type or not the same value, return `false`.
function isIdentical(x,y) {
return x === y
}
// 7. isEqual
// Define a function named `isEqual` that takes in two input arguments.
// If each argument is equal only in value, then return true. Otherwise return false.
function isEqual(x,y) {
return x == y
}
// 8. or
// Define a function named `or` that takes in two input arguments.
// The output returned should be the result of an `or` operation on both inputs.
function or(x,y) {
return x || y
}
// 9. and
// Define a function named `and` that takes in two input arguments and returns the
// result of a logical `and` operation of both inputs.
function and(x,y) {
return x && y
}
// 10. concat
// Define a function named `concat` that takes in two input arguments.
// If both arguments are strings, then return the concatenated result.
// If two numbers are provided, then return the string concatenation of each set of numerals.
function concat(x,y) {
return
}