SlideShare a Scribd company logo
Silicon Valley Code Camp
Learn JavaScript
by
Modeling Rubik’s Cube
Manoj Kumar
Agenda
• Scripting Language
• Crash course in Rubik’s Cube
• Code Walk-through
• Modeling
• Finding moves
Scripting Language
• Is a Programming Language
– To manipulate
– To customize
– To automate
– an existing system
• ECMAScript
– Web Scripting Language
– To work with web browser
ECMA Script
• Object Based
– Object: Collection of properties
– Property
• Type : Number, Boolean, String, Array, Function
& other objects
• Attributes
• Value, Writable, Configurable, Enumerable
• Functional
• Based on
– Java, C
– Self (Prototype)
– Scheme (Functional)
Types
• Primitive Value Types
– Number
– String
– Boolean
– Null
– Undefined
• Objects
• Functions
Number
• 64 bit floating point (sign bit, 11 exp, 52 frac)
• Represents integer and float
– 1, 3.45, 5.345e-10, 0377, 0xFF,
• Infinity
– >1.79769313486231570e+308
• NaN
– Nan != NaN
• Representation for
– MAX_VALUE, MIN_VALUE
– NEGATIVE_INFINITY, POSITIVE_INFINITY
• +0 == -0 but 1/+0 != 1/-0
String
• Within double/single quotes
– “Hello world”
– ‘u0041 world’
• Sequence of 16 bit unicode chars
• Supports + operator
• Used for character type too
Boolean
• Only two values
– true
– false
• 6 more falsy values
– 0, -0, “”, NaN, null, undefined
• Rest all values are true
– Including ‘false’ :)
Undefined and Null
• Undefined Type
– Only one value: undefined
• Null Type
– Only one value: null
Binary Operators
• Binary + (Addition or concatenation)
– 1 + 2 = 3,
– ‘1’ + ‘2’ = ‘1’ + 2 = 1 + ‘2’ = ‘12’
• -, * , /, %
– 2 * ‘3’ = 6
• >=, <=, >, <
• ==, !=
• === !==
• Logical &&, ||
Prefix Operators
• + to number
– 1 + +'2' // 3
• - negate
• ! logical not
• Typeof
– typeof 1 // ‘number’
– typeof ‘a’ // ‘string’
Bit Operators
• & and
• | or
• ^ xor
• ~ not
• >> signed right shift
• >>> unsigned right shift
• << left shift
And more
• = assignment
• +=, -=, *=, /= %=
– X op= y ==> x = x op y
• ++ increment
– X++ ==> x = x+1
• -- decrement
– X-- ==> x = x-1
A Simple Object
point = { x : 100, y : 200 };
point.x // 100
point[‘x’] // 100
point.y = 300;
ap = { “x-coord” : 100, “y-coord” : 200 };
ap.x-coord // Error, - means subtraction
ap[“x-coord”] // 100
ap[“X-coord”] // undefined, (note the upper
case X)
Functions
function add(x, y) {
return x+y
}
sum = add(4,5)
myAdd = add
sum1 = myAdd(4, 5)
Function Var
Assignment
myAdd = function add(x, y) {
return x+y
}
sum1 = myAdd(4, 5)
sum2 = add(4, 5)
ReferenceError: add is not defined
Function Var
Assignment
myAdd = function (x, y) {
return x+y
}
sum1 = myAdd(4, 5)
Anonymous Function
sum = function (x, y) {
return x+y
} (4,5)
Arguments
function add( ) {
var sum = 0
for( var i = 0; i < arguments.length; i++) {
sum += arguments[i]
}
return sum
}
add(4, 5) => 9
add(4,5,3) => 12
add() => 0
Scope of a Variable
function f() {
a = 6 // “a” is a global variable
}
a = 5
f()
// a is 6 now
Scope of a Variable
function f() {
var a = 6 // “a” is a local variable
alert("After assignment : a = " + a)
}
a = 5
alert("Before Calling function: a = " + a)
f()
alert("After Calling function: a = " + a)
Scope of a Variable
function f() {
a = 6
….
var a // makes “a” a local variable!
}
a = 5
f()
// a is still 5
Semicolon Insertion
You can only leave out ;
– Before }
A = 6 }
– After new line(s)
A = 6
}
– End of the program
Cannot leave ; within ‘for’ header
– for (var i=0; i < 7 .. NO ; inserted here
i++) {
Semicolon Insertion
Inserted only if next token cannot be parsed
A = 6 (; is inserted automatically)
X = 5
What if next line seems to be continuation?
A = b (; is NOT inserted automatically)
(add(3,4),......)
– So problem starting chars are
( [ + - /
– Statements before such chars must have ;
Building Custom Object
frontColor = { } // create empty
object
frontColor.red = 255
frontColor.blue = 0
frontColor.green = 128
redComponent = frontColor.red
Object using
constructor
function Color ( r, g, b ) {
this.red = r
this.green = g;
this.blue = b
}
red = new Color(255, 0, 0)
Object Using
Constructor
function Color ( r, g, b ) {
this.red = r
this.green = g;
this.blue = b
}
myColor = { }
myColor.red // undefined
Color.apply( myColor, [255, 65, 127] )
Color.call( myColor, 255, 65, 127 )
myColor.red // 255
Bad Usage of
Constructor
function Color ( r, g, b ) {
this.red = r
this.green = g
this.blue = b
}
Color(255, 127, 65)
this.red // 255.. but what is “this”
here?
Immutable Object Using
Constructor
function Color ( r, g, b ) {
this.getRed = function( ) { return r };
this.getGreen = function() { return g };
this.getBlue = function() { return b };
}
red = new Color(255, 0, 0)
red.getRed( ) // 255
red.red = 128 // creates a new property red
red.getRed() // still 255!
Closure
• Closure is an object having
– Function
– Environment when function was
created
• Local Variables of outer function
• Local functions declared in outer
function
• Parameters of outer function
• this and arguments of outer function are
not available but can be saved in local
variables of outer function and then
Property Attributes
• Value (Named Data Property)
– Default value
• Get and Set (Named Accessor Property)
– Getter and Setter function
– Either Value or Get/Set can be used, but not both
• Writable
– False => Read Only Property
• Enumerable
– False => Obj.keys or for (key in Obj) will not show
• Configurable
– False => delete obj.prop, or redefine will not work
Defining Property
function Color(r, g, b) {
Object.defineProperties( this,
{
red : {
value: r,
writable : false,
enumerable : true,
configurable: false
}, …
} ); }
Freezing an Object
Rubik = {};
Rubik.Slope = {};
Rubik.Slope.HORIZONTAL = "Horizontal";
Rubik.Slope.VERTICAL = "Vertical";
Rubik.Slope.SLANTED = "Slanted";
Rubik.Slope.ERROR = "Error";
Object.freeze(Rubik.Slope);
Object.defineProperty( Rubik, "Slope",
{ writable : false, enumerable : true,
configurable : false }
);
Sealing an Object
Object.seal(Rubik.Slope);
No new properties can be added.
Writable properties can be re-written.
Configurable properties can be re
configured.
Object.isSealed(Rubik.Slope) // true
Code Walkthrough
What next?
• DOM
• JQuery
• Java Script Design Patterns
• Coding Style/Documentation
• Books to read:
– JavaScript – The Good Parts
– Effective JavaScript
Many Variables in one
declaration
function X () {
var a = 5,
b = 6
var c = 7, d=8
alert ( "a=" + a + ", b=" + b + ", c="
+ c)
}
X()
//alert ( "a=" + a + ", b=" + b + ", c=" +
c)
Spot the mistake!
function X () {
var a = 5
b = 6
var c = 7
alert ( "a=" + a + ", b=" + this.b + ", c=" +
c)
}
X()
//alert ( "a=" + a + ", b=" + b + ", c=" + c)
alert ( "b=" + window.b)
Spot the mistake!
function X () {
var a = 5,
b = 6
var c = 7
alert ( "a=" + a + ", b=" + this.b + ", c=" +
c)
}
X()
//alert ( "a=" + a + ", b=" + b + ", c=" + c)
alert ( "b=" + window.b)
Constants in JavaScript
"use strict";
Object.defineProperty(this, "PI", {
value : 3.14,
writable : false,
enumerable : true,
configurable : false
});
PI = 7 // TypeError: "PI" is read-only
Constants in JavaScript
"use strict";
var MyConst = { }
MyConst.PI = 3.14
Object.freeze(MyConst)
MyConst.PI = 8 //TypeError: "PI" is read-only
Rubik’s Cube
• Cube
– Mini Cube/Cubelet/Atom
• Corner (8)
• Edge (12)
• Center (6)
– Sides/Layer
• Front/Back/Left/Right/Up/Down
Naming Atoms
• Corner: RFU
– Right, Front, Up corner
– RFU, FRU, URF … refers to same corner
• Edge : RF
– Middle cubelet of the edge shared by Right
and Front layers
• Center: R
– Center of the right layer
Moves
• R => right layer 90 deg clockwise
looking from right
• R’ => right layer 90 deg anticlockwise
looking from right
• R2 => right layer 180 deg
• RRRR, RR’, R2R2 =>No change
• (XY)’ = Y’X’
Effect of a Move
• Rotating front layer clockwise
( F) ==>
[ fru -> fdr -> fld -> ful -> fru ]
[ fr -> fd -> fl -> fu -> fr ]
• FRU ->FDR
– Corner FRU has moved to FDR
– Right side color of FRU has gone to Down side
of FDR
Useful Moves
• Moves that produce the minimal
disturbance
• One cycle of 3 corners (Placement)
• Rotating corners (Orientation)
• One cycle of 3 edges (Placement)
• In-place flipping edges (Orientation)
Basic Corners Moves
• One cycle of 3 corners
– (R'D'LD RD'L'D) => [ fru -> drf -> ful -> fru ]
– (RF'L'F R'F'LF) => [ fru -> lfu -> drf -> fru ]
• Rotate corner at its own place
(R'D'LD RD'L'D RF'L'FR'F'LF) ==>
[ dfr -> rdf ]
[ flu -> luf ]
Basic Edges Moves
• One cycle of 3 edges
(V'F2VF2) ==> [ fu -> bu -> fd -> fu ]
(V'F'VFFV'F'V) ==> [ fr -> fl -> df -> fr ]
• Flipping edges in its own positions
(RFBU2F2U'FUFU2B'R'F') ==>
[ fr -> rf ]
[ fu -> uf ]
Cube Representation
• Cube
• Atom
– Corner
– Edge
– Center
• Side
• Move
• MoveSequence
• MoveFinder
Built-in Objects
• Object
• Function
• Array
• String
• Boolean
• Number
• Math, Date, RegExp, JSON, Error
objects
Call and Apply
• add(4, 5, 2 ,3)
• add.call(null, 4, 5, 2, 3)
• add.apply(null, [4, 5, 2, 3])
• add.apply(undefined, [4, 5, 2, 3])
Variables
• No need to declare a variable
sum = 5
• Local Variables
var sum = 0;
• Declaring many variables in one declaration
var sum = 0, average = 0, stddev = 0;
• Always use semicolon OR know the rules
precisely
Object
• Collection of properties
• Property (optional)
– primitive value
– function
– other object
• Prototype (optional)
– To share property from others
Literal Object
frontColor = {
red : 255
blue : 0
green : 128
}
redComponent = frontColor.red
greenComponent = frontColor [ “green” ]
Immutable Object
function makeColor ( r, g, b ) {
return {
getRed : function( ) { return r },
getGreen : function() { return g },
getBlue : function() { return b }
}
}
color1 = makeColor(255, 0, 0)
color1.getRed( ) // 255
color1.getGreen() // 0
color1.blue = 128 // red has no property called blue!
Error!

More Related Content

What's hot (20)

PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance Trivia
Nikita Popov
 
Opaque Pointers Are Coming
Opaque Pointers Are ComingOpaque Pointers Are Coming
Opaque Pointers Are Coming
Nikita Popov
 
Deriving Scalaz
Deriving ScalazDeriving Scalaz
Deriving Scalaz
nkpart
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
Kazunobu Tasaka
 
Monad Transformers In The Wild
Monad Transformers In The WildMonad Transformers In The Wild
Monad Transformers In The Wild
StackMob Inc
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architecture
Jung Kim
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
Quinton Sheppard
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
vito jeng
 
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
Doris Chen
 
JavaScript For CSharp Developer
JavaScript For CSharp DeveloperJavaScript For CSharp Developer
JavaScript For CSharp Developer
Sarvesh Kushwaha
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
Kazunobu Tasaka
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScript
Joseph Smith
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
David de Boer
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
Alexis Gallagher
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
Nikita Popov
 
Introductionto fp with groovy
Introductionto fp with groovyIntroductionto fp with groovy
Introductionto fp with groovy
Isuru Samaraweera
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
Fwdays
 
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Doris Chen
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
Aung Baw
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance Trivia
Nikita Popov
 
Opaque Pointers Are Coming
Opaque Pointers Are ComingOpaque Pointers Are Coming
Opaque Pointers Are Coming
Nikita Popov
 
Deriving Scalaz
Deriving ScalazDeriving Scalaz
Deriving Scalaz
nkpart
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
Kazunobu Tasaka
 
Monad Transformers In The Wild
Monad Transformers In The WildMonad Transformers In The Wild
Monad Transformers In The Wild
StackMob Inc
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architecture
Jung Kim
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
Quinton Sheppard
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
vito jeng
 
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
Doris Chen
 
JavaScript For CSharp Developer
JavaScript For CSharp DeveloperJavaScript For CSharp Developer
JavaScript For CSharp Developer
Sarvesh Kushwaha
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScript
Joseph Smith
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
David de Boer
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
Alexis Gallagher
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
Nikita Popov
 
Introductionto fp with groovy
Introductionto fp with groovyIntroductionto fp with groovy
Introductionto fp with groovy
Isuru Samaraweera
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
Fwdays
 
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Doris Chen
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
Aung Baw
 

Viewers also liked (6)

OOPS in javascript
OOPS in javascriptOOPS in javascript
OOPS in javascript
Vijaya Anand
 
Multi-dimensional Programming The Rubik's Cube Challenge to Community Health ...
Multi-dimensional Programming The Rubik's Cube Challenge to Community Health ...Multi-dimensional Programming The Rubik's Cube Challenge to Community Health ...
Multi-dimensional Programming The Rubik's Cube Challenge to Community Health ...
CORE Group
 
Implementation of Rubik's Cube Formula in PyCuber
Implementation of Rubik's Cube Formula in PyCuberImplementation of Rubik's Cube Formula in PyCuber
Implementation of Rubik's Cube Formula in PyCuber
Wey-Han Liaw
 
Anatomia de una pagina web
Anatomia de una pagina webAnatomia de una pagina web
Anatomia de una pagina web
Constantino Centella
 
Step by Step guide for solving Rubik's Cube
Step by Step guide for solving Rubik's CubeStep by Step guide for solving Rubik's Cube
Step by Step guide for solving Rubik's Cube
Kush2K
 
Rubiks cube presentation
Rubiks cube presentationRubiks cube presentation
Rubiks cube presentation
cbartlo
 
OOPS in javascript
OOPS in javascriptOOPS in javascript
OOPS in javascript
Vijaya Anand
 
Multi-dimensional Programming The Rubik's Cube Challenge to Community Health ...
Multi-dimensional Programming The Rubik's Cube Challenge to Community Health ...Multi-dimensional Programming The Rubik's Cube Challenge to Community Health ...
Multi-dimensional Programming The Rubik's Cube Challenge to Community Health ...
CORE Group
 
Implementation of Rubik's Cube Formula in PyCuber
Implementation of Rubik's Cube Formula in PyCuberImplementation of Rubik's Cube Formula in PyCuber
Implementation of Rubik's Cube Formula in PyCuber
Wey-Han Liaw
 
Step by Step guide for solving Rubik's Cube
Step by Step guide for solving Rubik's CubeStep by Step guide for solving Rubik's Cube
Step by Step guide for solving Rubik's Cube
Kush2K
 
Rubiks cube presentation
Rubiks cube presentationRubiks cube presentation
Rubiks cube presentation
cbartlo
 
Ad

Similar to Learn JavaScript by modeling Rubik Cube (20)

JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)
Beat Signer
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3
BeeNear
 
13665449.ppt
13665449.ppt13665449.ppt
13665449.ppt
JP Chicano
 
Js in-ten-minutes
Js in-ten-minutesJs in-ten-minutes
Js in-ten-minutes
Phong Vân
 
JavaScript Good Practices
JavaScript Good PracticesJavaScript Good Practices
JavaScript Good Practices
Jussi Pohjolainen
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
MD Sayem Ahmed
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Mohammed Irfan Shaikh
 
3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOM
Jalpesh Vasa
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
yoavrubin
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
David Rodenas
 
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkkExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
kamalsmail1
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
Nitay Neeman
 
Intermediate JavaScript
Intermediate JavaScriptIntermediate JavaScript
Intermediate JavaScript
☆ Milan Adamovsky ☆
 
JavaScript Foundations Day1
JavaScript Foundations Day1JavaScript Foundations Day1
JavaScript Foundations Day1
Troy Miles
 
Web futures
Web futuresWeb futures
Web futures
Brendan Eich
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
Bedis ElAchèche
 
JS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better PartsJS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better Parts
JSFestUA
 
fundamentals of JavaScript for students.ppt
fundamentals of JavaScript for students.pptfundamentals of JavaScript for students.ppt
fundamentals of JavaScript for students.ppt
dejen6
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of Javascript
Universe41
 
JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)
Beat Signer
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3
BeeNear
 
Js in-ten-minutes
Js in-ten-minutesJs in-ten-minutes
Js in-ten-minutes
Phong Vân
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
MD Sayem Ahmed
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOM
Jalpesh Vasa
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
yoavrubin
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
David Rodenas
 
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkkExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
kamalsmail1
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
Nitay Neeman
 
JavaScript Foundations Day1
JavaScript Foundations Day1JavaScript Foundations Day1
JavaScript Foundations Day1
Troy Miles
 
JS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better PartsJS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better Parts
JSFestUA
 
fundamentals of JavaScript for students.ppt
fundamentals of JavaScript for students.pptfundamentals of JavaScript for students.ppt
fundamentals of JavaScript for students.ppt
dejen6
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of Javascript
Universe41
 
Ad

Recently uploaded (20)

THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
Julián Jesús Pérez Fernández
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
RVSPSOA
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly WorkshopsLDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDM & Mia eStudios
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
RVSPSOA
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly WorkshopsLDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDM & Mia eStudios
 

Learn JavaScript by modeling Rubik Cube

  • 1. Silicon Valley Code Camp Learn JavaScript by Modeling Rubik’s Cube Manoj Kumar
  • 2. Agenda • Scripting Language • Crash course in Rubik’s Cube • Code Walk-through • Modeling • Finding moves
  • 3. Scripting Language • Is a Programming Language – To manipulate – To customize – To automate – an existing system • ECMAScript – Web Scripting Language – To work with web browser
  • 4. ECMA Script • Object Based – Object: Collection of properties – Property • Type : Number, Boolean, String, Array, Function & other objects • Attributes • Value, Writable, Configurable, Enumerable • Functional • Based on – Java, C – Self (Prototype) – Scheme (Functional)
  • 5. Types • Primitive Value Types – Number – String – Boolean – Null – Undefined • Objects • Functions
  • 6. Number • 64 bit floating point (sign bit, 11 exp, 52 frac) • Represents integer and float – 1, 3.45, 5.345e-10, 0377, 0xFF, • Infinity – >1.79769313486231570e+308 • NaN – Nan != NaN • Representation for – MAX_VALUE, MIN_VALUE – NEGATIVE_INFINITY, POSITIVE_INFINITY • +0 == -0 but 1/+0 != 1/-0
  • 7. String • Within double/single quotes – “Hello world” – ‘u0041 world’ • Sequence of 16 bit unicode chars • Supports + operator • Used for character type too
  • 8. Boolean • Only two values – true – false • 6 more falsy values – 0, -0, “”, NaN, null, undefined • Rest all values are true – Including ‘false’ :)
  • 9. Undefined and Null • Undefined Type – Only one value: undefined • Null Type – Only one value: null
  • 10. Binary Operators • Binary + (Addition or concatenation) – 1 + 2 = 3, – ‘1’ + ‘2’ = ‘1’ + 2 = 1 + ‘2’ = ‘12’ • -, * , /, % – 2 * ‘3’ = 6 • >=, <=, >, < • ==, != • === !== • Logical &&, ||
  • 11. Prefix Operators • + to number – 1 + +'2' // 3 • - negate • ! logical not • Typeof – typeof 1 // ‘number’ – typeof ‘a’ // ‘string’
  • 12. Bit Operators • & and • | or • ^ xor • ~ not • >> signed right shift • >>> unsigned right shift • << left shift
  • 13. And more • = assignment • +=, -=, *=, /= %= – X op= y ==> x = x op y • ++ increment – X++ ==> x = x+1 • -- decrement – X-- ==> x = x-1
  • 14. A Simple Object point = { x : 100, y : 200 }; point.x // 100 point[‘x’] // 100 point.y = 300; ap = { “x-coord” : 100, “y-coord” : 200 }; ap.x-coord // Error, - means subtraction ap[“x-coord”] // 100 ap[“X-coord”] // undefined, (note the upper case X)
  • 15. Functions function add(x, y) { return x+y } sum = add(4,5) myAdd = add sum1 = myAdd(4, 5)
  • 16. Function Var Assignment myAdd = function add(x, y) { return x+y } sum1 = myAdd(4, 5) sum2 = add(4, 5) ReferenceError: add is not defined
  • 17. Function Var Assignment myAdd = function (x, y) { return x+y } sum1 = myAdd(4, 5)
  • 18. Anonymous Function sum = function (x, y) { return x+y } (4,5)
  • 19. Arguments function add( ) { var sum = 0 for( var i = 0; i < arguments.length; i++) { sum += arguments[i] } return sum } add(4, 5) => 9 add(4,5,3) => 12 add() => 0
  • 20. Scope of a Variable function f() { a = 6 // “a” is a global variable } a = 5 f() // a is 6 now
  • 21. Scope of a Variable function f() { var a = 6 // “a” is a local variable alert("After assignment : a = " + a) } a = 5 alert("Before Calling function: a = " + a) f() alert("After Calling function: a = " + a)
  • 22. Scope of a Variable function f() { a = 6 …. var a // makes “a” a local variable! } a = 5 f() // a is still 5
  • 23. Semicolon Insertion You can only leave out ; – Before } A = 6 } – After new line(s) A = 6 } – End of the program Cannot leave ; within ‘for’ header – for (var i=0; i < 7 .. NO ; inserted here i++) {
  • 24. Semicolon Insertion Inserted only if next token cannot be parsed A = 6 (; is inserted automatically) X = 5 What if next line seems to be continuation? A = b (; is NOT inserted automatically) (add(3,4),......) – So problem starting chars are ( [ + - / – Statements before such chars must have ;
  • 25. Building Custom Object frontColor = { } // create empty object frontColor.red = 255 frontColor.blue = 0 frontColor.green = 128 redComponent = frontColor.red
  • 26. Object using constructor function Color ( r, g, b ) { this.red = r this.green = g; this.blue = b } red = new Color(255, 0, 0)
  • 27. Object Using Constructor function Color ( r, g, b ) { this.red = r this.green = g; this.blue = b } myColor = { } myColor.red // undefined Color.apply( myColor, [255, 65, 127] ) Color.call( myColor, 255, 65, 127 ) myColor.red // 255
  • 28. Bad Usage of Constructor function Color ( r, g, b ) { this.red = r this.green = g this.blue = b } Color(255, 127, 65) this.red // 255.. but what is “this” here?
  • 29. Immutable Object Using Constructor function Color ( r, g, b ) { this.getRed = function( ) { return r }; this.getGreen = function() { return g }; this.getBlue = function() { return b }; } red = new Color(255, 0, 0) red.getRed( ) // 255 red.red = 128 // creates a new property red red.getRed() // still 255!
  • 30. Closure • Closure is an object having – Function – Environment when function was created • Local Variables of outer function • Local functions declared in outer function • Parameters of outer function • this and arguments of outer function are not available but can be saved in local variables of outer function and then
  • 31. Property Attributes • Value (Named Data Property) – Default value • Get and Set (Named Accessor Property) – Getter and Setter function – Either Value or Get/Set can be used, but not both • Writable – False => Read Only Property • Enumerable – False => Obj.keys or for (key in Obj) will not show • Configurable – False => delete obj.prop, or redefine will not work
  • 32. Defining Property function Color(r, g, b) { Object.defineProperties( this, { red : { value: r, writable : false, enumerable : true, configurable: false }, … } ); }
  • 33. Freezing an Object Rubik = {}; Rubik.Slope = {}; Rubik.Slope.HORIZONTAL = "Horizontal"; Rubik.Slope.VERTICAL = "Vertical"; Rubik.Slope.SLANTED = "Slanted"; Rubik.Slope.ERROR = "Error"; Object.freeze(Rubik.Slope); Object.defineProperty( Rubik, "Slope", { writable : false, enumerable : true, configurable : false } );
  • 34. Sealing an Object Object.seal(Rubik.Slope); No new properties can be added. Writable properties can be re-written. Configurable properties can be re configured. Object.isSealed(Rubik.Slope) // true
  • 36. What next? • DOM • JQuery • Java Script Design Patterns • Coding Style/Documentation • Books to read: – JavaScript – The Good Parts – Effective JavaScript
  • 37. Many Variables in one declaration function X () { var a = 5, b = 6 var c = 7, d=8 alert ( "a=" + a + ", b=" + b + ", c=" + c) } X() //alert ( "a=" + a + ", b=" + b + ", c=" + c)
  • 38. Spot the mistake! function X () { var a = 5 b = 6 var c = 7 alert ( "a=" + a + ", b=" + this.b + ", c=" + c) } X() //alert ( "a=" + a + ", b=" + b + ", c=" + c) alert ( "b=" + window.b)
  • 39. Spot the mistake! function X () { var a = 5, b = 6 var c = 7 alert ( "a=" + a + ", b=" + this.b + ", c=" + c) } X() //alert ( "a=" + a + ", b=" + b + ", c=" + c) alert ( "b=" + window.b)
  • 40. Constants in JavaScript "use strict"; Object.defineProperty(this, "PI", { value : 3.14, writable : false, enumerable : true, configurable : false }); PI = 7 // TypeError: "PI" is read-only
  • 41. Constants in JavaScript "use strict"; var MyConst = { } MyConst.PI = 3.14 Object.freeze(MyConst) MyConst.PI = 8 //TypeError: "PI" is read-only
  • 42. Rubik’s Cube • Cube – Mini Cube/Cubelet/Atom • Corner (8) • Edge (12) • Center (6) – Sides/Layer • Front/Back/Left/Right/Up/Down
  • 43. Naming Atoms • Corner: RFU – Right, Front, Up corner – RFU, FRU, URF … refers to same corner • Edge : RF – Middle cubelet of the edge shared by Right and Front layers • Center: R – Center of the right layer
  • 44. Moves • R => right layer 90 deg clockwise looking from right • R’ => right layer 90 deg anticlockwise looking from right • R2 => right layer 180 deg • RRRR, RR’, R2R2 =>No change • (XY)’ = Y’X’
  • 45. Effect of a Move • Rotating front layer clockwise ( F) ==> [ fru -> fdr -> fld -> ful -> fru ] [ fr -> fd -> fl -> fu -> fr ] • FRU ->FDR – Corner FRU has moved to FDR – Right side color of FRU has gone to Down side of FDR
  • 46. Useful Moves • Moves that produce the minimal disturbance • One cycle of 3 corners (Placement) • Rotating corners (Orientation) • One cycle of 3 edges (Placement) • In-place flipping edges (Orientation)
  • 47. Basic Corners Moves • One cycle of 3 corners – (R'D'LD RD'L'D) => [ fru -> drf -> ful -> fru ] – (RF'L'F R'F'LF) => [ fru -> lfu -> drf -> fru ] • Rotate corner at its own place (R'D'LD RD'L'D RF'L'FR'F'LF) ==> [ dfr -> rdf ] [ flu -> luf ]
  • 48. Basic Edges Moves • One cycle of 3 edges (V'F2VF2) ==> [ fu -> bu -> fd -> fu ] (V'F'VFFV'F'V) ==> [ fr -> fl -> df -> fr ] • Flipping edges in its own positions (RFBU2F2U'FUFU2B'R'F') ==> [ fr -> rf ] [ fu -> uf ]
  • 49. Cube Representation • Cube • Atom – Corner – Edge – Center • Side • Move • MoveSequence • MoveFinder
  • 50. Built-in Objects • Object • Function • Array • String • Boolean • Number • Math, Date, RegExp, JSON, Error objects
  • 51. Call and Apply • add(4, 5, 2 ,3) • add.call(null, 4, 5, 2, 3) • add.apply(null, [4, 5, 2, 3]) • add.apply(undefined, [4, 5, 2, 3])
  • 52. Variables • No need to declare a variable sum = 5 • Local Variables var sum = 0; • Declaring many variables in one declaration var sum = 0, average = 0, stddev = 0; • Always use semicolon OR know the rules precisely
  • 53. Object • Collection of properties • Property (optional) – primitive value – function – other object • Prototype (optional) – To share property from others
  • 54. Literal Object frontColor = { red : 255 blue : 0 green : 128 } redComponent = frontColor.red greenComponent = frontColor [ “green” ]
  • 55. Immutable Object function makeColor ( r, g, b ) { return { getRed : function( ) { return r }, getGreen : function() { return g }, getBlue : function() { return b } } } color1 = makeColor(255, 0, 0) color1.getRed( ) // 255 color1.getGreen() // 0 color1.blue = 128 // red has no property called blue! Error!