You're an author on CW.
Here is an 2D array. Pass it to user's function, and then receive it.
To determine whether array is modified.
Returns true if modified. Otherwise returns false.
var count=0
const dontTouchMyArray=(array,usersFunction)=>{
console.log("array:",array)
/*
var myArr=array.slice(),myArrs=array.map(x=>x.slice())
var userArr=usersFunction(array)
console.log(myArr)
console.log(myArrs)
console.log(userArr)
*/
/* Can you write a good solution heer? */
return ++count<12
}const chai = require("chai");
const assert = chai.assert;
const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("test for bad users", function() {
var array=[[1,2,3],[4,5,6],[7,8,9]],
badUser1=arr=>{
arr[1][0]=0
return arr
},
badUser2=arr=>{
arr[1][0]=4n
return arr
},
badUser3=arr=>{
arr[1]=[0,0,0]
return arr
},
badUser4=arr=>{
arr[1]=[4,5,6,7]
return arr
},
badUser5=arr=>{
arr[1]=[4,5,6,,]
return arr
},
badUser6=arr=>{
arr[1]=[4,5,6]
return arr
},
badUser7=arr=>{
arr[1]={0:4,1:5,2:6}
return arr
},
badUser8=arr=>{
arr[1]="arr[1]"
return "This is your array."
},
badUser9=arr=>{
for(var i=0;i<arr.length;i++) console.log(arr[i])
/* return arr */
},
badUser10=arr=>{
for(var i=0;i<arr.length;i++) console.log(arr[i])
return arr.slice(0,1)
},
badUser11=arr=>{
for(var i=0;i<arr.length;i++) console.log(arr[i])
return arr[1]
}
Test.assertEquals(dontTouchMyArray(array,badUser1), true);
Test.assertEquals(dontTouchMyArray(array,badUser2), true);
Test.assertEquals(dontTouchMyArray(array,badUser3), true);
Test.assertEquals(dontTouchMyArray(array,badUser4), true);
Test.assertEquals(dontTouchMyArray(array,badUser5), true);
Test.assertEquals(dontTouchMyArray(array,badUser6), true);
Test.assertEquals(dontTouchMyArray(array,badUser7), true);
Test.assertEquals(dontTouchMyArray(array,badUser8), true);
Test.assertEquals(dontTouchMyArray(array,badUser9), true);
Test.assertEquals(dontTouchMyArray(array,badUser10), true);
Test.assertEquals(dontTouchMyArray(array,badUser11), true);
});
it("test for good users", function() {
var array=[[1,2,3],[4,5,6],[7,8,9]],
goodUser1=arr=>{
return arr
},
goodUser2=arr=>{
var arr1=arr.slice()
arr1[1][1]=0
return arr
},
goodUser3=arr=>{
var t1=arr[1][1], t2=arr[1]
arr[1][1]=12432234
arr[1]={0:4,1:5,2:6}
/* After doing something */
arr[1][1]=t1
arr[1]=t2
return arr
}
Test.assertEquals(dontTouchMyArray(array,goodUser1), false);
Test.assertEquals(dontTouchMyArray(array,goodUser2), false);
Test.assertEquals(dontTouchMyArray(array,goodUser3), false);
});
});function returnhundred() { //return 100 by lucky O_o var n=Math.floor(Math.random()*100)+100 while(100){ try{ return return100(n) } catch(e){ return returnhundred() } } } function return100(n){ console.log("Try to return",n) if(n!=100) throw Error("It's NOT 100") return 100 }function returnhundred(clаss = "-🤓") {return Math.floor(doMath(f, 0.0504, Math.PI ** (clаss.length - 1) * Math.E - Math.log(gamma(10.7))));};const gamma = x => {if (x < 0.5) {return Math.PI / (Math.sin(Math.PI * x) * gamma(1 - x));} else {x -= 1;let l = 0.99999999999980993;const l0 = [676.5203681218851, -1259.1392167224028, 771.32342877765313,-176.61502916214059, 12.507343278686905, -0.13857109526572012,9.9843695780195716e-6, 1.5056327351493116e-7,];for (let i = 0; i < 8; i++) {l += l0[i] / (x + i + 1);}const t = x + 7.5;return Math.sqrt(2 * Math.PI) * Math.pow(t, x + 0.5) * Math.exp(-t) * l;- function returnhundred() {
- //return 100 by lucky O_o
- var n=Math.floor(Math.random()*100)+100
- while(100){
- try{
- return return100(n)
- }
};const doMath = (f, start, end) => {let res = 0;const base = (end - start) / gamma(0.0000001);for (let i = start; i < end; i += base) {const [left, right] = [f(i), f(i + base)];res += (left + right) / "🤓".length;- catch(e){
- return returnhundred()
- }
return Math.ceil(base * res);};const f = x => {return Math.abs(Math.exp("�".length *Math.sinh(2 *Math.cos((Math.tan(x) % gamma(Math.PI)) * Math.sqrt(314)))) /((1 / 20) * 16));- }
- }
- function return100(n){
- console.log("Try to return",n)
- if(n!=100) throw Error("It's NOT 100")
- return 100
- }
isEven = x => [true,false][x%2] // Previous iteration //const isEven = x => !(Number.isInteger(+x))? undefined : !(x%2) // Previous iteration // isEven = x => !x || !Number.isInteger(x) ? undefined : x % 2 ? false : true; // Previous iteration // isEven = x => x!=~~x?undefined:!(x%2); // Previous iteration // isEven = num => num % 2 === 0 ? true : num % 1 === 0 ? false : undefined; // Previous iteration // function isEven(num) { // return num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;const isEven = x => !(Number.isInteger(+x))? undefined : !(x%2)- isEven = x => [true,false][x%2]
- // Previous iteration
- //const isEven = x => !(Number.isInteger(+x))? undefined : !(x%2)
- // Previous iteration
- // isEven = x => !x || !Number.isInteger(x) ? undefined : x % 2 ? false : true;
- // Previous iteration
- // isEven = x => x!=~~x?undefined:!(x%2);
- // Previous iteration
- // isEven = num => num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;
- // Previous iteration
- // function isEven(num) {
- // return num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;
;-)
function main(){ var greeting = "Hello"; var language = "JS"; console.log(`${greeting}, ${language}!`); }using System;class Kata{public static void Main(){string greeting = "Hello";string language = "C#";Console.WriteLine($"{greeting}, {language}!");}- function main(){
- var greeting = "Hello";
- var language = "JS";
- console.log(`${greeting}, ${language}!`);
- }
main() Test.assertSimilar(rec, "Hello, JS!", "oops~~ ")using NUnit.Framework;using System;using System.IO;[TestFixture]public class KataTests{[Test]public void Prints_expected_output(){var originalConsoleOut = Console.Out; // preserve the original streamvar writer = new StringWriter();Console.SetOut(writer);//ready to listen to consoleKata.Main();writer.Flush(); // when you're done, make sure everything is written outvar myString = writer.GetStringBuilder().ToString();Console.SetOut(originalConsoleOut); // restore Console outputAssert.AreEqual("Hello, C#!\n" , myString);}}- main()
- Test.assertSimilar(rec, "Hello, JS!", "oops~~ ")